popen on windows

hubritic colinlandrum at gmail.com
Tue Jan 2 12:01:45 EST 2007


Thanks for your reply. I figured it out. I was not closing the file
that path pointed to before executing the command. D'oh! So sometimes
it read the file that was created on the previous test run ...

Anyway, for the benefit of anyone who might be googling for a similar
question, what seems to work for running a command in Windows and
having it wait for the command to finish was (after closing the file
before I refer to it) was:

(this is python 2.4.3. I think subprocess was new in 2.4. See
documentation for subprocess module)

from subprocess import Popen
r = Popen(string_with_the_command, shell=True)
r.wait()

Sometimes the hardest part of python is to resist the urge to imagine
that things *must* be complicated and therefore the simpliest possible
solution can't possibly work ...



Daniel Klein wrote:
> On 27 Dec 2006 09:16:53 -0800, "hubritic" <colinlandrum at gmail.com>
> wrote:
>
> >I am trying to set off commands on Windows 2003 from python.
> >Specifically, I am trying to use diskpart with a script file (pointed
> >to with path).
> >
> >            cmd = ["diskpart",  "/s", path]
> >            p = Popen(cmd, shell=True)
> >
> >The script is meant to loop through twice. It will do so if I comment
> >out the Popen call and print cmd instead. But when Popen is called, one
> >disk will be formated, but not the next.
>
> What is the value of 'path' ?
> 
> Does the command work from a Windows command prompt ?
> 
> Dan




More information about the Python-list mailing list