469,909 Members | 1,617 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

pty.spawn directs stderr to stdout

Hi,

using pty.spawn() it seems that stderr output of the spawned process is
directed to stdout. Is there a way to keep stderr separate and only direct
stdin and stdout to the pty?

TIA,
w best regards,
Wilbert Berendsen

--
http://www.wilbertberendsen.nl/
"You must be the change you wish to see in the world."
-- Mahatma Gandhi
Apr 11 '08 #1
4 5302
In article <ma**************************************@python.o rg>,
Wilbert Berendsen <wb****@xs4all.nlwrote:
Hi,

using pty.spawn() it seems that stderr output of the spawned process is
directed to stdout. Is there a way to keep stderr separate and only direct
stdin and stdout to the pty?
There is, of course.

First, you have to decide where you want unit 2 ("stderr") to go, and
then get the spawned process to redirect it there. If a disk file
will do, then your question is just "how do I redirect error output
to a disk file, in ___" (fill in the blank with language used to
implement the spawned process - UNIX shell? Python? C?)

More likely, you want the spawned process' error output to go wherever
the parent's error output was going. This is a little trickier.

Ideally, your spawned shell script can conveniently take a new
parameter that identifies the new file descriptor unit number for
error output. In this case, use fd2 = os.dup(2) to get a new
duplicate, add a parameter like -e str(fd2), and in the spawned
process, redirect from that unit - in UNIX shell, exec 2>&$fd2

Or you could use an environment variable to identify the backup
error unit, if the command line parameter option isn't available
for some reason.

Donn Cave, do**@u.washington.edu
Apr 11 '08 #2
In article <ma**************************************@python.o rg>,
Wilbert Berendsen <wb****@xs4all.nlwrote:
Hi,

using pty.spawn() it seems that stderr output of the spawned process is
directed to stdout. Is there a way to keep stderr separate and only direct
stdin and stdout to the pty?
There is, of course.

First, you have to decide where you want unit 2 ("stderr") to go, and
then get the spawned process to redirect it there. If a disk file
will do, then your question is just "how do I redirect error output
to a disk file, in ___" (fill in the blank with language used to
implement the spawned process - UNIX shell? Python? C?)

More likely, you want the spawned process' error output to go wherever
the parent's error output was going. This is a little trickier.

Ideally, your spawned shell script can conveniently take a new
parameter that identifies the new file descriptor unit number for
error output. In this case, use fd2 = os.dup(2) to get a new
duplicate, add a parameter like -e str(fd2), and in the spawned
process, redirect from that unit - in UNIX shell, exec 2>&$fd2

Or you could use an environment variable to identify the backup
error unit, if the command line parameter option isn't available
for some reason.

Donn Cave, do**@u.washington.edu
Jun 27 '08 #3
Op vrijdag 11 april 2008, schreef Donn Cave:
More likely, you want the spawned process' error output to go wherever
the parent's error output was going. *This is a little trickier.
I ended up writing a small script that basically reimplements fork() from the
pty module, where then STDERR is not dup'ed to the pty.

I'm currently trying to combine subprocess.Popen with pty.openpty ...

tx,
Wilbert Berendsen

--
http://www.wilbertberendsen.nl/
"You must be the change you wish to see in the world."
-- Mahatma Gandhi
Jun 27 '08 #4
Op zaterdag 12 april 2008, schreef Wilbert Berendsen:
I'm currently trying to combine subprocess.Popen with pty.openpty ...
which succeeded :-)
http://code.google.com/p/lilykde/sou...unpty.py?r=314
it seems to work :-)
thanks,
Wilbert Berendsen

--
http://www.wilbertberendsen.nl/
"You must be the change you wish to see in the world."
-- Mahatma Gandhi
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mark Roach | last post: by
6 posts views Thread by Tsai Li Ming | last post: by
2 posts views Thread by Abhishek | last post: by
5 posts views Thread by Wesley Henwood | last post: by
1 post views Thread by =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post: by
2 posts views Thread by Guillaume Dargaud | last post: by
1 post views Thread by Lincoln Yeoh | last post: by
1 post views Thread by EEK | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.