473,671 Members | 2,572 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read from stdouton Popen on WinXP?

I am trying to run a program and filter the output on Windows XP.
Since I want to filter the output, I'd like to read it a line at a time
and only print the lines I care about.

p = subprocess.Pope n(["doxygen.ex e", r"Doxyfile.c fg"],
stdout=subproce ss.PIPE, stderr=subproce ss.STDOUT)
while 1:
line = p.stdout.readli ne()
if not line:
break
print line
The problem is that readline() only returns after the whole process has
completed. I have tried various permutations such as using os.read()
and changing the bufsize parameter and using popen4. To no avail.

Obviously, it should be possible to read stdout before the process
completes, since if I leave off the "stdout=" parameter, the full
output shows up in stdout in "realtime" as you'd expect.

About the only thing I can come up with is to pipe the .exe to another
python script which could communicate to the main script via TCP/IP,
but that seems ridiculous. I searched the newsgroup and didn't see
anything particularly helpful.

Anyone have a non-ridiculous solution?

Aug 16 '05 #1
1 1485
mhenry1384 a écrit :
I am trying to run a program and filter the output on Windows XP.
Since I want to filter the output, I'd like to read it a line at a time
and only print the lines I care about. [snip]


I had the exact same problem yesterday. This is an obvious use case for
the "bufsize" parameter to os.popen4, except that the Windows
implementation doesn't accept anything but -1...

The only way I can see out of this is to use win32api to launch the
process through CreateProcess, then perform asynchronous I/O on its
stdout using the OVERLAPPED structure in a call to ReadFile... Ugly...
Aug 17 '05 #2

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

Similar topics

9
3408
by: Bryan | last post by:
i have a batch file that contains these two lines: -- args.bat echo %1 echo %2 when i run args.bat from the command line it works correctly... notice that abc has quotes in the first example and not in the second.
0
1643
by: David H | last post by:
Background. I'm running on WinXP w/ MS Services for Unix installed (to give rsh/rlogin ability), both Python 2.3 and 2.4 version. In linux, I'm running RHEE with python2.3 version. The code below works fine for me in linux, but in WinXP the popen*() command "hangs". More specifically, I get an apparent python prompt (without the '>>> ', but whatever I type has no effect, and hitting return does a CR but not the additional LF, so I...
16
2669
by: Chris Maloof | last post by:
Hello, Does anyone know how I can read the ASCII text from a console window (from another application) in WinXP? It doesn't sound like a major operation, but although I can find the window via pywin32, I haven't been able to do anything with it. I'd really just like to get the window text into a string. By "console window", I mean the sort of thing that comes up when you run "command" (although this particular one is for the game...
17
5250
by: bastiaannaber | last post by:
I am trying to write a program which uses popen but I have a problem. I want to detect if the program I call with popen has ended. For example: #include <stdio.h> #include <sys/types.h> #include <unistd.h> int main() { FILE *pipe = NULL;
5
1920
by: manokumar | last post by:
hiye, i notice that some if not all of my folders in winxp pro. are set as read only and its giving me some problem with development. so as the natural thing, i unchecked the read only option and click apply then click ok. and when i right click on the same folder again JUST TO MAKE SURE the read only option is checked AGAIN. so again, unchecked, and again its check and the cycle repeats. anyway, i'm the administrator to this computer. so...
9
9367
by: Clodoaldo Pinto Neto | last post by:
Output from the shell: $ set | grep IFS IFS=$' \t\n' Output from subprocess.Popen(): "IFS=' \t\n" Both outputs for comparison:
5
4329
by: nic | last post by:
On my system (WinXP) typing the following line into command prompt(cmd.exe) successfully scans the file test1.txt: "c:\Program Files\Grisoft\AVG Free\avgscan.exe" "c:\program files\temp1\test1.txt" Yet the python script: import os a = os.popen('"c:\Program Files\Grisoft\AVG Free\avgscan.exe" "c:\program files\temp1\test1.txt"') print a.read()
2
6274
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 os import sys file = os.popen("nslookup", 'w') file.write("google.com\n") file.close()
3
7816
by: Jesse | last post by:
Hi all, I have a problem using wget and Popen. I hope someone can help. -- Problem -- I want to use the command: wget -nv -O "dir/cpan.txt" "http://search.cpan.org" and capture all it's stdout+stderr. (Note that option -O requires 'dir' to be existing before wget is executed) Popen doesn't work, while os.system and shell do. Popen will give the error:
0
8825
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...
1
8605
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6237
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5703
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
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
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
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
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.