[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lua system interaction on win
- From: read.beyond.data@...
- From: Celvin <read.beyond.data@...>
- Date: Tue, 20 Aug 2002 17:55:17 -0300
- Date: Tue, 20 Aug 2002 22:56:02 +0200
At 21:52 20.08.2002 +0200, you wrote:
- start an external process and read it's output.
- bonus: write to the stdin of the external process
Now lua compiled for Windows doesn't support the '| command' functionality
for readfrom(), as it doesn't have 'pipes'
Of course one could use a construct like
execute("dir > temp.txt")
o = read("*a")
But is there a nicer way to do that in Windows?
As you already stated, it can be done via the WinAPI. Actually, it's rather
simple. You spawn the process you want to read from/write to via a call to
CreateProcess(). Here it comes in handy that the STARTUPINFO structure
passed as an argument to CreateProcess() has
three members (among others), called: hStdInput, hStdOutput and hStdError.
What you do now is set hStdOutput (and in most cases hStdError, too) to a
handle you obtained via a call to CreatePipe().
You may set hStdIn to either GetStdHandle(STD_INPUT_HANDLE) or, if you wish
to access stdin as well, create another pipe. Afterwards, you can
read/write to the pipes via ReadFile/WriteFile...
I hope this is of some use to you....