lua-users home
lua-l archive

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

Hi all!

Recently I tried to use io.popen to read the output produced by some
shell commands (in Windows XP).

The problem is that io.popen only returns a handle to stdout for the
child process. If I want to capture stderr apparently I have only two

(1) to redirect it to a file and then read it back.
(2) to forfeit stdout and redirect stderr to stdout.
(3) merge stdout and stderr using XP redirection tricks.

None of the above suits my needs. I need both stdout AND stderr output
so this rules out (2), while (3) is not general enough (I cannot be sure
I can parse stdout and stderr apart).

(1) is a tradeoff, but I'd like not to write anything on disk if possible.

Is there a way to do it in pure Lua?

I searched the WIKI to no avail, and in lua-l archive there are only
very old posts. The only recent messages I found were about two-way
popen (not supported and considered unreliable without threading), but I
don't need to both read and write, I only need to read both output streams.

Is it possible in pure Lua (5.2 would be enough)?

If not, may I suggest to enhance io.popen in Lua 5.3, e.g. by returning
two handles, one to stdout and one to stderr. I guess (hope?) it
shouldn't be too hard or cause problems or add relevant bloat. BTW wxLua
implements a similar functionality in wx.wxExecuteStdoutStderr, which
captures the two streams independently.


-- Lorenzo

()  ascii ribbon campaign - against html e-mail
/\   - against proprietary attachments