Redirecting stdin/stdout/setderr and os.execv

Steve Holden sholden at holdenweb.com
Wed Jan 16 11:59:58 EST 2002


"Richard Philips" <Richard.Philips at ua.ac.be> wrote ...
>
> How do I redirect stdin, stdout en stderr from within a python script
> together with os.execv:
>
>
> import os
> import sys
>
> sys.stdout = open("/tmp/output","wb")
> os.execv("/bin/ls", ["ls", "-ls"])
>
>
> does not redirect the stdout of the /bin/ls
>
> Any ideas on this ?
>
> I am looking for a replacement for os.system which is independent of the
> pecularities of the shell in use.
>
You probably need the os.popen() function or one of its buddies
popen2.popen2(), os.popen3(), popen2.popen3() , etc, which create file-like
pipeline objects you can read the output from and write standard input to.
In short, look in modules os and popen2 for names beginning with popen!

regards
 STeve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list