473,394 Members | 1,787 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,394 software developers and data experts.

Run child process with stdout and result on Win32?

Is there really no way to run a sub-process, gather its stdout/stderr,
and collect the return-code, on Win32???
But that's what the docs say...
These methods do not make it possible to retrieve the return code
from the child processes. The only way to control the input and
output streams and also retrieve the return codes is to use the
Popen3 and Popen4 classes from the popen2 module; these are only
available on Unix.


Surely not!?!?

Dave.

Jul 18 '05 #1
1 2085
Dave Sellars <da**@didnt.freeserve.co.uk> wrote in
news:40***********************@news.easynet.co.uk:
Is there really no way to run a sub-process, gather its stdout/stderr,
and collect the return-code, on Win32???
But that's what the docs say...
These methods do not make it possible to retrieve the return code
from the child processes. The only way to control the input and
output streams and also retrieve the return codes is to use the
Popen3 and Popen4 classes from the popen2 module; these are only
available on Unix.


Surely not!?!?

Dave.


Bizarrely, the return code is returned as the result of the *last* call to
the close method on any of the file handles returned. i.e. You must close
all of stdin, stdout and stderr handles returned (usually after
reading/writing), and the last one you close will return a numeric exit
code if the command returned a non-zero exit code. If the command returned
a 0 exit code then the final close returns None.
from popen2 import popen2
fout, fin = popen2("dir c:\\temp")
print fout.close(), fin.close() None None fout, fin = popen2("dir c:\\xxx")
print fout.close(), fin.close() None 1 fout, fin = popen2("dir c:\\xxx")
print fin.close(), fout.close() None 1


So far as I can see, the documentation omits to mention this little fact (I
read the source).
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tung Wai Yip | last post by:
I've build the following utility. It works so far but I want to make sure I'm doing the right thing. I am running Python 2.3 on windows 2000. def execute(cmd): """ execute cmd in sub-process,...
2
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
0
by: rtm | last post by:
I am interested in running a process with a timeout. Also I'm interested in analyzing the output of this process. Under Unix, the solution is described clearly in the Perl Cookbook "16.10: ...
3
by: Mike Finister | last post by:
Hi there At the moment I am writing a GUI front-end that in the background is to call some scripts on a Unix box. The GUI has to be written in Visual Basic (yes I said the VB word...sorry! :-) )...
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...
0
by: danebarney | last post by:
I'm developing a Windows CE 5.0 app using C# and I need to call a child process and then capture its stdout into a window. The solutions I've read online for doing this involve either using the...
2
by: Greg Ercolano | last post by:
When I use os.popen(cmd,'w'), I find that under windows, the stdout of the child process disappears, instead of appearing in the DOS window the script is invoked from. eg: C:\type foo.py import...
22
by: Jason Zheng | last post by:
This may be a silly question but is possible for os.wait() to lose track of child processes? I'm running Python 2.4.4 on Linux kernel 2.6.20 (i686), gcc4.1.1, and glibc-2.5. Here's what happened...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.