[Tutor] Popen and sending output to a file

Ertl, John john.ertl at fnmoc.navy.mil
Wed Jan 19 19:49:47 CET 2005


That is too easy.  I was looking at the examples of how to replace the old
popen and I just did not get it but the page you sent is great.  

John 

-----Original Message-----
From: Danny Yoo [mailto:dyoo at hkn.eecs.berkeley.edu]
Sent: Wednesday, January 19, 2005 10:34
To: Ertl, John
Cc: tutor at python.org
Subject: Re: [Tutor] Popen and sending output to a file


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