[Tutor] Popen and sending output to a file
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Wed Jan 19 19:33:32 CET 2005
On Wed, 19 Jan 2005, Ertl, John wrote:
> I am using the subprocess.Popen from 2.4. I can launch a job from
> python and the output from the job goes to the screen but now I would
> like to have the output go to a file. I could do the crude
>
> subprocess.Popen("dtg | cat > job.out", shell=True)
>
> But I would think there is a better way built into Popen but I could not
> figure out the documentation.
Hi John,
According to:
http://www.python.org/doc/lib/node227.html
we can redirect standard input, output, and error by calling Popen with
the 'stdin', 'stdout', or 'stderr' keyword arguments.
We should be able to do something like:
###
job_output = open("job.out", "w")
subprocess.Popen("dtg", shell=True, stdout=job_output)
###
Best of wishes to you!
More information about the Tutor
mailing list