subprocess.Popen question
Nobody
nobody at nowhere.com
Tue Aug 16 07:26:39 EDT 2011
On Tue, 16 Aug 2011 02:03:50 -0500, Danny Wong (dannwong) wrote:
> I'm executing a command which I want to capture the
> standard/stderr output into a file (which I have with the code below),
> but I also want the standard output to go into a variable so I can
> process the information for the next command. Any ideas? Thanks.
>
> CMD_OUTPUT = subprocess.Popen(COMMAND, stdout=PROJECT_LOGFILE,
> stderr=subprocess.STDOUT)
CMD_OUTPUT.wait()
with open(PROJECT_LOGFILE,'r') as f:
str = f.read()
If you're going to be writing it to a file anyhow, reading that file is
likely to be faster than the alternatives.
More information about the Python-list
mailing list