lua-users home
lua-l archive

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

May have missed the complete story here, but,
Whats the the problem with using the WIN32
_popen(), _pclose() ???
In my WIN32 build I used

... /D popen=_popen /D pclose=_pclose ...

and readfrom("|dir") was fine

----- Original Message -----
From: <>; "Celvin" <>
To: "Multiple recipients of list" <>
Sent: Wednesday, August 21, 2002 6:55 AM
Subject: Re: lua system interaction on win

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