python equivalent of the following program

Steven Bethard steven.bethard at
Thu May 11 22:06:36 CEST 2006

AndyL wrote:
> What would by a python equivalent of following shell program:
>     #!/bin/sh
>     prog1 > file1 &
>     prog2 > file2 &

If you're just going for quick-and-dirty, Rob's suggestion of os.system 
is probably a reasonable way to go.  If you want better error reporting, 
I suggest using open() and the subprocess module:

import subprocess

file1 = open('file1', 'w')
prog1 = subprocess.Popen(['prog1'], stdout=file1)

file2 = open('file2', 'w')
prog2 = subprocess.Popen(['prog2'], stdout=file2)

If at some point later you want to make sure that the processes 
completed, you simply call .wait() on prog1 or prog2.


More information about the Python-list mailing list