Starting a subprocess from Python

May 5, 2008

subprocess is a convenient way to fork a new process on Windows/Unix/etc. It obsoletes previous methods such as commands (which does not support Windows) and os.system()/os.popen*/os.spawn*

Here is an example:
import subprocess
cmd_lst = ['exec_file', 'arg1', 'arg2', ...]
subprocess.call(cmd_lst) #return the value returned by the callee
subprocess.check_call(cmd_lst) #return if the callee exits with 0, otherwise raise an error

Entry Filed under: All, notes. .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

May 2008
M T W T F S S
« Apr   Jun »
 1234
567891011
12131415161718
19202122232425
262728293031  

Most Recent Posts