|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello everybody,
I am trying to run .exe file from python script and i want to stop further execution of python script untill .exe file is closed. is there any command or way to do this? I tried to use system command. but after it opens .exe file, it goes to next statement for further execution. it want stop until .exe file is closed. Everything is welcome. Thanks in Advance ![]() |
|
#2
|
||||
|
||||
|
You're best bet would be to use os.popen(), which i believe will start and stay with the current process untill finished. Though im pretty sure os.system() will do this - can't say i've really tried to start an exe and wait for processes before sorry.
Now Pythons homepage is back up heres the link to the OS module: http://www.python.org/doc/2.3.4/lib/module-os.html Hope this helps, Mark. Last edited by netytan : July 12th, 2004 at 11:29 PM. Reason: Adding link to 'os' as promised |
|
#3
|
|||
|
|||
|
Hii Mark,
I tried using os.popen(). It is just like os.system(). It want stop to wait for .exe program to stop or closed. Please any other way. is there any other command to wait for .exe program to finish in accordance with os.popen or os.system? Like wait()... Thanks. Waitng for reply... Devhims |
|
#4
|
||||
|
||||
|
There is time.sleep() but unless you know how long the exe is going to run for it probably wont do you any good. Of course, if you new the program was going to run for at the most 30 seconds you could make Python sleep for that long.
Mark. |
|
#5
|
||||
|
||||
|
How about something like this:
Code:
import popen2
buff = 1024 #A nice big number to take any possible output
#in between reads
proc = popen2.Popen4("MyProg.exe",buff)
while proc.poll() == -1:
print "My prog is still running"
And do something useful .....
print "The program finished with exit code", proc.poll()
It works very well under Linux and Windows and you have the advantage of being able to read it's output with the fromchild method. grim ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
|
#6
|
|||
|
|||
|
Re: execution stop until execution finished
You could use os.fork() to create a child process. The child would then os.popen() or whatever to execute your external app and the parent would waitpid() (after doing some optional work if it needs to), waiting for the child to os.exit() . I don't know if it works on windows, though.
|
|
#7
|
|||
|
|||
|
os.system() should always wait for the program to finish - in fact it has to on most systems, since it returns the exit code. Are you sure it is continuing? Can you show us your code? What OS are you running on?
Dave - The Developers' Coach |
|
#8
|
|||
|
|||
|
Thanks to everyone for their reply. Now it is working . I used
os.spawnl(mode,...) command. with mode = os.P_WAIT. But sometime it hangs computer and you have to close pyton program manually. As soon as you closed it, (.exe)program will open on which python was spawn. I do not why it does that. May be due to lack of memory. Most of the time it works fine. Still i will try with os.fork() and let you guys know. One more by any chance anybody know how to minimize opened .exe file or run it in background.? So, end-use want know from where it is running. DevHims |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > is there way to stop execution of pythonscript until it finish execution of .exe? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|