473,385 Members | 2,015 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,385 software developers and data experts.

popen and a long running process in a wx.python application

Hello,

How can I capture the output of a long runnning process which I open
with popen() ?
I tried reading line by line, char by char, but the result always
comes when the process finishes.
(I am trying to make a wx.python program that opens some "make ..."
with popen). How can I receive the output of the program immediatly,
so that I can show a progressbar in my application ?
I always get the program's output after it finished executing.
Is this the right place, or should I post this to wx.python ?

Thank you in advance.

Jun 26 '07 #1
3 2088
On Jun 26, 10:16 am, Doru Moisa <moisad...@gmail.comwrote:
Hello,

How can I capture the output of a long runnning process which I open
with popen() ?
I tried reading line by line, char by char, but the result always
comes when the process finishes.
(I am trying to make a wx.python program that opens some "make ..."
with popen). How can I receive the output of the program immediatly,
so that I can show a progressbar in my application ?
I always get the program's output after it finished executing.
Is this the right place, or should I post this to wx.python ?

Thank you in advance.
When talking about anything advanced with wxPython, you usually want
to submit it to the wxPython user's group. Lots of advanced users
(including the author of wxPython) answer questions there.

I would recommend looking at the following link as this will probably
be one of the first suggestions:
http://wiki.wxpython.org/index.cgi/L...longrunning%29

wxPython mailing list: http://www.wxpython.org/maillist.php

I used a variation of one of the threading example in the
LongRunningTasks page to send output to a text widget, through stdout
redirection.

Good luck!

Mike

Jun 26 '07 #2
On Jun 26, 10:16 am, Doru Moisa <moisad...@gmail.comwrote:
Hello,

How can I capture the output of a long runnning process which I open
with popen() ?
I tried reading line by line, char by char, but the result always
comes when the process finishes.
(I am trying to make a wx.python program that opens some "make ..."
with popen). How can I receive the output of the program immediatly,
so that I can show a progressbar in my application ?
I always get the program's output after it finished executing.
Is this the right place, or should I post this to wx.python ?

Thank you in advance.


I think this is the right list to post this in since it's independent
of wxPython.
I just recently went through this and got it working properly. Your
problem is that the output is buffered and is only flushed upon exit
(and that's when you read() it)
Here's a piece of code:

doRead = True
p = subprocess.Popen(["ls"], stdout=sp.PIPE, stderr=sp.STDOUT,
bufsize=1)
while doRead:
txt = os.read(p.stdout.fileno(), 2048)
time.sleep(0.5) # read at most x times / sec

A few things to note:
(1) you must use os.read and not the builtin read() for unbuffered
read.
(2) you probably want to run this while loop in a thread because read
will block until there's some text available
(3) this is a polling method where I read at most 2 a second in the
above example
(4) this works on Mac, Windows and Linux the same (besides the "ls"
command of course)
(5) after you read this text you can send it to a TextCtrl or
something

Hope that helps.

Ratko

Jun 26 '07 #3

Mike, Ratko,

Thanks a lot guys, for the quick and prompt answers.

Doru
Jun 27 '07 #4

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: Maarten van Veen | last post by:
A long story made short, I've build a python/cgi website consisting of two pages. Page1 has a html form in which you can input a series of queries. Then via Popen it starts a pythons search script,...
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...
8
by: dmoore | last post by:
Hi folks, I've seen the following issue come up in multiple posts to this mailing list: I have a python program that spawns a child process with popen or popen2 or popen3 or popen2.popen2...
3
by: Ratko | last post by:
Hi all, I have a python gui app that launches multiple applications using subprocess.Popen class and prints their output in the gui (using PIPEs, threads and wxPython). Everything works great...
1
by: walterbyrd | last post by:
I understand that Python has them, but PHP doesn't. I think that is because mod_php is built into apache, but mod_python is not usually in apache. If mod_python was built into apache, would...
4
by: commander_coder | last post by:
Hello, I write a lot of CGI scripts, in Python of course. Now I need to convert some to long-running processes. I'm having trouble finding resources about the best practices to do that. ...
4
by: zane.selvans | last post by:
Hi there, I've been banging my head against this for a day, and I can't take it anymore. It's probably a stupid error, but I don't see where. I'm trying to use Python to call an external...
25
by: Jeremy Banks | last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the Popen class in the subprocess module. Popen sounds like the a suitable name for a function that created a subprocess, but the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.