lua-users home
lua-l archive

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


You can use Luaposix to do the same Posix commands bash would do in
your script to achieve the same thing. Or you wrap a "bash -c" around
the call again, to use bash functionality just like you used to.

I just wonder what you expect to get as answer of the whole call, if B writes
\033[2J              -- clear screen
\033[0#;0H        --- goto 0/0
FOOBAR
\033[0#;0H         --- goto 0/0
MUH
?

do you expect to get all the terminal codes? Or do you want to get
"MUHBAR" what then will be seen on the terminal screen?

IMHO, PTYs and Piping don't mix well (been there tried that), and if
you feel the need to do it, you might want to go a different solution
path somewhere else.

On Tue, Mar 13, 2012 at 7:30 PM, Bernd Eggink <monoped@sudrala.de> wrote:
> Hi all,
>
> what I'm missing most in the standard IO library is the possibility to
> choose arbitrary file descriptors. The problem is, I have a Lua program A
> from which I start an xterm which executes program B:
>
>        os.execute("xterm -e B")
>
> At exit, B prints a result, which I want to read and process in A. A pipe
> doesn't help here, because
>
>        io.popen("xterm -e B")
>
> reads the output of xterm (which is always empty), while the output of B
> goes into nirwana.
>
> In bash (I'm on Linux, as you may have guessed) I would do this:
>
>        result=$(xterm -e "B >&3" 3>&1)
>
> but it seems that an equivalent trick is not possible in Lua. I can of
> course use a temporary file, but I wonder if there is a more elegant way in
> Lua?
>
> Bernd
>
> --
> Bernd Eggink
> http://sudrala.de
>