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

popen child termination

How can I make popen (popen2, popen3) run and finish inside my program?

Example:

def Run(cmd):
w,r,e = os.popen3(cmd)
w.close()
r.close()
e.close()
Run('touch ~/xxx')
os.remove('~/xxx')

The example above fails with this error message for os.remove: "No such
file or directory: '~/xxx'"

But when the os.remove line is deleted, the example correctly creates
the xxx file.

I feel that os.wait() deals with this but I do not understand how to use
it to do what I want.

--
Milos Prudek
Jul 18 '05 #1
1 1685
Quoth Milos Prudek <pr****@bvx.cz>:
| How can I make popen (popen2, popen3) run and finish inside my program?
|
| Example:
|
| def Run(cmd):
| w,r,e = os.popen3(cmd)
| w.close()
| r.close()
| e.close()
| Run('touch ~/xxx')
| os.remove('~/xxx')
|
| The example above fails with this error message for os.remove: "No such
| file or directory: '~/xxx'"
|
| But when the os.remove line is deleted, the example correctly creates
| the xxx file.
|
| I feel that os.wait() deals with this but I do not understand how to use
| it to do what I want.

You're right, but you're going to have to back up a little and
do the popen part a little different.

popen() itself is simpler, because the wait() is built into the
pclose(3) function that's called by the close() method. You will
find that it returns exit status, except when exit status is 0 in
which case it returns None. (Did that make sense? I hope not.)

As for popen3(), you will need to instead create the Popen3 instance
that popen3 creates. Then you can invoke its wait() method. There
isn't any way to get there from just the file objects that popen3()
returns.

Donn Cave, do**@drizzle.com
Jul 18 '05 #2

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

Similar topics

1
by: Matthew K Jensen | last post by:
I've been trying to find a way to detect when a command run by os.popen (or similar) has completed (in Windows, btw). I found such a function (i don't remember the exact name and library), but the...
5
by: Michele Simionato | last post by:
I was looking at Python 2.4 subprocess.Popen. Quite nice and handy, but I wonder why a "kill" method is missing. I am just adding it via subclassing, class Popen(subprocess.Popen): def...
2
by: I. Myself | last post by:
I read in the docs that "bufsize=1" causes line buffering. (for subprocess.Popen) The following tiny program launches an executable file and then receives its output. That works, but I want to...
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...
2
by: revenant81 | last post by:
I'm writing a program which has to execute a command, get its output and show it on a treeview. This command runs for a very long time. I want to end the execution of the command when the user...
3
by: Mathieu Prevot | last post by:
Hi it seems the script (A) finishes before the downloading ends, and the (B) version doesn't (wanted behavior) ... this is unexpected. What happens ? (A)...
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...
5
by: thedsadude | last post by:
Hello, I'm launching a script as follows: <code> p = subprocess.Popen() p.wait() </code> If p.py writes to sys.stdout, then it is shown on the console.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.