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

waiting for a program run by popen3() to end

Hi,
I have some code that runs an interactive program via popen3(). The program generates
output which is then used later on. My script looks like this:

o,i,e = os.popen3('/usr/local/adapt/bin/descmng -g')
o.write('\n%s\n\n' % (redpick))
o.close()
time.sleep(1)
os.system('mv set5 gendes.in && rm set? outputdesc.txt')

The program (descmng) produces the files set?, outputdesc.txt

However on some systems, the program takes more than 1 sec to complete
and as a result the os.system() command fails.

Increasing the sleep time to 5 sec solves the problem but it does'nt seem to
be reliable.

I have considered using fork() and wait() but that does'nt let me run the
program interactively.

Is there any other way out (apart from dumping commands to a file and
piping them to my program in a fork())?

Thanks,
Jul 18 '05 #1
2 7547
Quoth Rajarshi Guha <ra******@presidency.com>:

| I have some code that runs an interactive program via popen3(). The program generates
| output which is then used later on. My script looks like this:
|
|
|
| o,i,e = os.popen3('/usr/local/adapt/bin/descmng -g')
| o.write('\n%s\n\n' % (redpick))
| o.close()
| time.sleep(1)
| os.system('mv set5 gendes.in && rm set? outputdesc.txt')
|
| The program (descmng) produces the files set?, outputdesc.txt
|
| However on some systems, the program takes more than 1 sec to complete
| and as a result the os.system() command fails.
|
| Increasing the sleep time to 5 sec solves the problem but it does'nt seem to
| be reliable.
|
| I have considered using fork() and wait() but that does'nt let me run the
| program interactively.
|
| Is there any other way out (apart from dumping commands to a file and
| piping them to my program in a fork())?

You should look at the popen2 module in the library. You're using
it already, via os.popen3, but the classes in popen2.py provide more
features. However, it seems to me that you should be able to synch
with the child process by simply reading from its output or error
files. Whether it actually outputs any data or not, when the process
exits, those pipes should close and the read will finish. If you're
not interested in the data, though, I would not redirect error output
and throw it away as you're doing here, and if you redirect only the
regular output, that will greatly reduce odds of a deadlock.

Or even simpler, you can add the other statements to the command
to be run by os.popen3.

Donn Cave, do**@drizzle.com
Jul 18 '05 #2
Hello Rajarshi,
o,i,e = os.popen3('/usr/local/adapt/bin/descmng -g')
o.write('\n%s\n\n' % (redpick))
o.close()
time.sleep(1)
os.system('mv set5 gendes.in && rm set? outputdesc.txt') If you're not reading the program output you can use os.system which
will wait for it to end.
Is there any other way out (apart from dumping commands to a file and
piping them to my program in a fork())?

On Unix like systems there is popen2.Popen3 (or Popen4)
---
from popen2 import Popen3

print "Running child"
p = Popen4("my_process arg1 arg2")
print "Waiting"
p.wait() # Will wait for process to end
print "And we got:"
print p.fromchild.read()
---

HTH.
Miki
Jul 18 '05 #3

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

Similar topics

2
by: selwyn | last post by:
hi all, I would like some advice on how I can include a timeout for a scanning operation using unzip on linux and os.popen3. I am scanning through about 30g of rescued zip files, looking for...
4
by: Chris Green | last post by:
Hey folks, I'm whipping up a quick CGI to wrap a command line app and I was a bit suprised to not find a execl-like Popen3 style object. I don't want to bother with the shell interpreting...
0
by: Jeffrey Barish | last post by:
My Tkinter GUI starts a thread that runs ogg123 using popen3. The thread reads the stderr from ogg123 to determine when ogg123 is done and, until then, to update a progress meter. I need to be...
1
by: oziko | last post by:
Hi, I am trying to read ogg123's output with popen3: stin, sto, ste = os.popen3('ogg123 music.ogg') out=sto.readlines() The problem is I can not get any text from the output when I read...
1
by: Ruchika | last post by:
Hi, I am trying to automate the build process for which I need to run P4 commands from the Python script. After getting sources from Perforce, I need to build them using Visual C++ from the...
13
by: Russell E. Owen | last post by:
I'm trying to launch an application from Python 2.3 on Windows. The application is "ds9" (an image viewer), and is installed in C:\Program Files\ds9\ds9 On unix I just do: os.popen3("ds9") and...
2
by: Jakob Simon-Gaarde | last post by:
Follow-up on a thread from 1999 (see below) Well now it is 2005 and the operating system I'm using is Windows Server 2003, and I can still see that the same problem persists with: ...
1
by: Fuzzyman | last post by:
Hello all, I may well post this a a bug on Monday (after testing with Python 2.3) - but I thought I'd post here to see if anyone has any ideas. The basic problem is that under Python 2.4 (and...
4
by: Lad | last post by:
How can I run external program from Python? I use Python with XP Thank you for help LB
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.