473,800 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5776
In article <ma************ *************** ***********@pyt hon.org>,
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.washingt on.edu
Apr 11 '08 #2
In article <ma************ *************** ***********@pyt hon.org>,
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.washingt on.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.Pope n 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.Pope n 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
3012
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 printer1 %s' % (filename)) def daemonize(func): """cookbook recipe from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012"""
6
5640
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.* . I have tried the simplest method of capturing stdout, stderr via: saveout = sys.stdout sys.stdout = file_obj
1
2676
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 greatly appreciated. Thanks, Sri
2
2863
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 string into the corresponding streams. But can you please tellme where does the content go exactly when we put it into the above streams. In which cases can we see the outpt and in which cases cant we see and why so? It would be great if you can...
5
2611
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"); PyRun_SimpleString("class a:\n\tdef write(self,s):\n\t\tograbber.grab(s)\n"); PyRun_SimpleString("import sys\nsys.stderr=a()\nsys.stdout=a()"); Its hard to read that way, here's what it expands to:
1
3770
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 capture the results of the compile and display them in a RichTextBox. The problem I'm having is that when I intentionally introduce an error in the C code I'm compiling, I can't read the error output in my C# program. I've tried redirecting both...
2
8511
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 separate files, but would rather keep the 2 flows together. Is it correct to do this: stderr=freopen(LogFile, "w", stderr); stdout=freopen(LogFile, "a", stdout);
1
6703
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 own stderr? Say I have a program called foo: #!/usr/bin/python
1
3192
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 file, respectively. I've been able to make this work with subprocess.Popen only if the shell variable is set to False but I cannot pipe the outputs of the targets.
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10279
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10036
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.