views:

97

answers:

2

In a bash script, I can write:

exec 2>&1
exec someprog

And the stderr output of someprog would be redirected to stdout.

Is there any way to do a similar thing using python's os.exec* functions?

This doesn't have to be portable, just work on Linux.

+2  A: 

You could use the subprocess module instead of os.exec*:

subuprocess.call(['prog', 'param'], stderr=subprocess.STDOUT)
sth
subprocess does a very different thing from what I'm trying to do. I use exec to replace python with a new binary, and I don't need python to hang around.
itsadok
+1  A: 

os.dup2(1, 2)

Ignacio Vazquez-Abrams