Skip to content

Instantly share code, notes, and snippets.

@sysnajar
Created October 20, 2015 11:31
Show Gist options
  • Select an option

  • Save sysnajar/8ece7ea2695d090f8033 to your computer and use it in GitHub Desktop.

Select an option

Save sysnajar/8ece7ea2695d090f8033 to your computer and use it in GitHub Desktop.
quick one
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
Longgggggggggger explainations
http://lua-users.org/lists/lua-l/2010-09/msg00955.html
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment