From: fredrik at pythonware.com (Fredrik Lundh)
Date: Sun, 23 May 1999 13:45:56 GMT
Subject: Newbie question...
References: <7i3hg0$3mi$1@elle.eunet.no>
Message-ID: <020901bea522$b07a78c0$f29b12c2@pythonware.com>
X-UID: 1795                                                

Christian Tellefsen wrote:
> ... I just started programming in Python (today!)
> 
> I want to run a few OS commands from python (on Win NT),
> but I cannot find a way to wait for the commands to finish.
> 
> Source:
> **
> os.system ('c:\ntreskit\sc stop "' + serviceA + '"')
> os.system ('c:\ntreskit\sc stop "' + serviceB + '"')
> os.system ('c:\ntreskit\sc stop "' + serviceC + '"')
> **

oops.  did you forget that \n is a newline?

> 
> Is there a way I can ensure that each command finishes before the next line
> in the script is executed?

starting with Python 1.5.2, you can use os.spawnv:

status = os.spawnv(os.P_WAIT, "c:\\ntreskit\\sc", ("stop", serviceA))
(untested)

http://www.python.org/doc/current/lib/os-process.html
has the full story.

</F>





