[Tutor] Python 2.2... os.exec catch stdout

Lie Ryan lie.1296 at gmail.com
Fri Jun 5 08:19:16 CEST 2009


Chris Mueller wrote:
> /Hello.
> 
> I am relegated to running python 2.2; so I do not have access to subprocess.
> 
> In my script; at one point, I need to run a program; interact with the
> program; exit the  program; and parse the output printed to stdout.
> 
> This would be simple; if I did not need to interact with my
> sub-program..  I currently have..
> 
> import os
> program = "vim"
> arguments = ["myFile"]
> pid = os.fork()
> if not pid:
>     os.execvp(program, (program,) + tuple(arguments))
> os.wait()[0]
> 
> This works fine; lets me interact with "vim" fine; and return to the
> python script when I am done; but I do not seem to be able to execute
> read stdout; and all examples I have found on the net do not allow me to
> interact with the called program.
> 
> Any pokes int he right direction?
> 
> Thanks,
>     Chris

Use the subprocess module.

The os.execvp terminates your program and replace it with the new
process; you can't catch the stdout from a terminated process



More information about the Tutor mailing list