lua-users home
lua-l archive

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


On 2010-07-06, David Manura <dm.lua@math2.org> wrote:
> On Tue, Jul 6, 2010 at 8:52 PM, Hisham <hisham.hm@gmail.com> wrote:
>> ...given that io.popen can only do reading or writing but not both...
>
> Lacking anything else, bidirectional piping could be implemented by
> writing to a temporary file.  I recall discussions on this problem in
> the past, e.g. [1].
>
>   [1] http://lua-users.org/lists/lua-l/2007-10/msg00241.html
>

I've always worked around this by creating two named pipes in a
temporary directory, and piping the app's stdout and stderr to them,
i.e.:
exec(program .. " >/tmp/mystdout 2>/tmp/mystderr")
Compared to temporary files, it has the advantage of not actually
writing the data to disk, so space and performance aren't a big deal.
I'm not sure if you can create named pipes on Windows though.
Really if you want to support Windows, that's another can of worms
entirely... for example the "don't duplicate shell constructs" rule
doesn't work as well when you're not sure the shell has them.

-- 
Sent from my toaster.