spawnlp, spawnvp and stdout-redirection
Marc Saric
marc.saric at mpi-dortmund.mpg.de
Fri Aug 30 09:33:22 EDT 2002
Hi all,
I recently tried to write a small script which runs a bunch of external
programs in paralell (3 at a time) on a UNIX-machine. The external
programs should redirect their output to a logfile.
Here's the relevant code:
import os
list1 = [1,2,3,4]
list2 = [1,2,3]
for i in list1:
x =[]
for j in list2:
x.append(os.spawnlp(os.P_NOWAIT, 'myprogram', 'myprogram',
'-option1', 'infile1', 'infile2', 'infile3'))
for p in x:
os.waitpid(p,0)
Essentially this does what it should: Start three external programs,
wait until they are finished, start the next three, etc.
Here comes the problem:
I wanted something similar to (csh)
myprogram > logfile -option1 infile1 infile2 infile3
which works pretty well on the console.
If I try to do this with os.spawnlp(os.P_NOWAIT, 'myprogram',
'myprogram', '> logfile', '-option1', 'infile1', 'infile2', 'infile3')
or similar ('>', 'logfile' or 'myprogram > logfile') it fails.
I have no clue how to redirect output while directly calling the
program. It works again with a little hack (a csh-script which takes
everything as an argument, and is called by the python-script), but it
is a bit ugly.
I have searched this newsgroup and the doc, but haven't found a sollution.
If someone knows a way to solve this problem...
Thanks in advance!
--
Bye, Marc Saric
Max-Planck-Institut fuer molekulare Physiologie
Otto-Hahn-Str.11 44227 Dortmund phone:0231/133-2168
More information about the Python-list
mailing list