Newbie question...
Fredrik Lundh
fredrik at pythonware.com
Sun May 23 09:45:56 EDT 1999
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>
More information about the Python-list
mailing list