lua-users home
lua-l archive

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


Hello list!

I have a problem that seems to be rather simple for *IX systems that have
pipes, but I need to do this in windows.

Task:
- start an external process and read it's output.
- bonus: write to the stdin of the external process

on systems that support pipes the following example code works fine:

-- invoke the 'ls' command
-- NOTE 'ls' is just an example
-- goal is to use any programm that outputs data to stdout
h = readfrom("| ls -l") -- this will fail on win
o = read("*a") -- read from it's stdout
closefile(h)
-- do something with o
print(o)

(obviously the 'ls' command needs to be replaced with something like 'dir'
on win)

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?
(I've done this kind of thing from VB, using the win32 API...)
Or would I need to handle this in some platform specific lib?

I'd be happy for any ideas/pointers

Thanks, Martin