[Tutor] Capture command output

Kent Johnson kent37 at tds.net
Thu Nov 3 11:55:16 CET 2005


Johan Geldenhuys wrote:
> I've been musy with the os command on how to kill a process. That's been 
> sorted out to an extend. Many thanks for your input.
> 
> Now I have a question in the same direction:
> 
> I use os.execpv(cmd, [cmd, args]). That executes the command that have 
> output. This was the best way of getting the pid and killing the process 
> after a certain time.
> 
> How do I capture that output to a file?
> Can I use os.popen() or something like that after I did the os.execvp() 
> execution or is there a standard way of putting any output in a file/

Have you tried using subprocess.Popen()? It supports capturing output of the child process and it gives access to the pid of the child.

Kent

-- 
http://www.kentsjohnson.com



More information about the Tutor mailing list