473,414 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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 5752
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark Roach | last post by:
I am using the daemonize (double-fork) code from the cookbook, and have bumped into a strange issue. This is what my program is doing: def main(): ... useful things ... os.popen('/usr/bin/lp -d...
6
by: Tsai Li Ming | last post by:
Dear all, I have a problem with a redirecting stdout and stderr. I am a top level module and has no control over the imported modules that are making system calls such as os.system or popen2.* ....
1
by: SG | last post by:
Hello, I'm using _execvpe (Win32 console project in VS.NET) to spawn a child process. I would like to know if you have any pointers on how to capture the child's STDOUT and STDERR? Any help is...
2
by: Abhishek | last post by:
what are the STDUPDATE, STDERR, STDOUT and STDIN streams and how does one access these streams in C language. I am aware of the function fprintf(FILE *fp, char * format, char *s) which puts the...
5
by: Wesley Henwood | last post by:
To capture output from python scripts run from a C++ app I've added the following code at the beggening of the C++ app: PyRun_SimpleString("import grabber"); PyRun_SimpleString("import sys");...
1
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a C# application in which I start another process which produces output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++ compiler itself! I would like to...
2
by: Guillaume Dargaud | last post by:
Hello all, a while ago I was pointed towards freopen as a way to redirect stderr to a log file. It works great, but apparently the app also writes a few lines to stdout. Now I could redirect to 2...
1
by: Lincoln Yeoh | last post by:
Hi, I've just started to learn python (I've been using perl for some years). How do I redirect ALL stderr stuff to syslog, even stderr from external programs that don't explicitly change their...
1
by: EEK | last post by:
Hello, My goal is to start and stop separate Linux processes from a python program by specific PID. The output of these processes needs to have their stderr and stdout piped to a particular...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.