lua-users home
lua-l archive

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


On Tue, Sep 28, 2010 at 00:23,  <pj@pjb.com.au> wrote:
> Greetings.
>
> Is it possible to
>  local pipe = io.popen(command, 'rb')
> and then get access to any stderr output it may produce ?
>
> This comes from trying to translate from Python:
>  pipe = subprocess.Popen(command, shell=True,
>    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>  midi = pipe.stdout.read()
>  msg  = pipe.stderr.read()
>
> Regards,  Peter Billam
>
> http://www.pjb.com.au       pj@pjb.com.au      (03) 6278 9410
> "Was der Meister nicht kann,   vermöcht es der Knabe, hätt er
>  ihm immer gehorcht?"   Siegfried to Mime, from Act 1 Scene 2
>
>
>

You can use redirection:
pipe = io.popen('ls 2>&1', 'rb') --gives both stdout and stderr in pipe
pipe = io.popen('ls 2>/tmp/stderr', 'rb') --redirects stderr to file
(obviously generate a name less likely to be in use if you go this route)

I don't think Lua offers a way to read both streams separately without
redirecting one to a pipe or temporary file.

-- 
Sent from my toaster.