Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ipython notebook output from child process

When using ipython notebook, the output of child processes spawned by subprocess never shows up in the notebook itself. For example, this cell

import subprocess
subprocess.check_call(['echo', 'hello'])

Only shows 0 as output, and the hello is printed on the terminal where ipython is launched.

Is there any configuration parameters I can tune such that the output of child processes show up in the notebook itself?


Actually custom python c extensions will also have their output swallowed. Is there any fix?

like image 766
Siyuan Ren Avatar asked Jan 24 '15 14:01

Siyuan Ren


1 Answers

Use check_output if you want the output captured. check_call returns the exit code.

import subprocess
print subprocess.check_output(['echo', 'hello'])
like image 73
Amit Verma Avatar answered Oct 25 '22 19:10

Amit Verma