[IPython-User] catching system call's output in notebook
Thomas Kluyver
takowl@gmail....
Mon Feb 6 13:22:20 CST 2012
On 6 February 2012 19:15, Julian Taylor <jtaylor.debian@googlemail.com>wrote:
> use the subprocess module instead of os.system:
>
> import subprocess
> print subprocess.check_output(["./test"])
>
To explain some more about the difference: when you do os.system, it's not
capturing stdout/stderr from the new process. In the terminal, this works,
because stdout and stderr just go directly to the terminal, without Python
ever knowing about them. In the notebook, it doesn't, because the kernel
can only forward stdout/stderr that it knows about.
subprocess.check_output() captures stdout and returns it. If you need to
capture stderr as well, refer to the docs:
http://docs.python.org/library/subprocess#subprocess.check_output
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20120206/8ee0deb9/attachment.html
More information about the IPython-User
mailing list