Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 12th, 2004, 09:47 AM
DevHims DevHims is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 DevHims User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question is there way to stop execution of pythonscript until it finish execution of .exe?

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

Reply With Quote
  #2  
Old July 12th, 2004, 10:41 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.
__________________
programming language development: www.netytan.com Hula


Last edited by netytan : July 12th, 2004 at 11:29 PM. Reason: Adding link to 'os' as promised

Reply With Quote
  #3  
Old July 12th, 2004, 12:08 PM
DevHims DevHims is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 DevHims User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

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

Reply With Quote
  #4  
Old July 12th, 2004, 12:13 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #5  
Old July 12th, 2004, 01:44 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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 ***

Reply With Quote
  #6  
Old July 12th, 2004, 03:05 PM
sandro sandro is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Belgium
Posts: 3 sandro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #7  
Old July 12th, 2004, 03:54 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,221 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 22 h 21 m 4 sec
Reputation Power: 263
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

Reply With Quote
  #8  
Old July 12th, 2004, 05:35 PM
DevHims DevHims is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 27 DevHims User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > is there way to stop execution of pythonscript until it finish execution of .exe?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT