lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


At 21:52 20.08.2002 +0200, you wrote:
Task:
- 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")
readfrom("temp.txt")
o = read("*a")
print(o)

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....