popen on windows

H

hubritic

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.
 
D

Daniel Klein

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
 
H

hubritic

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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top