Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subprocess.Call fails "The System Cannot Find the File Specified"

Tags:

python

I have a .exe file called Manipula that takes as its source a .msu file. I can successfully run what I want through the command line like so:

"C:/Flow Check/Run Quick/Applications/Manipula.exe" "C:/Flow Check/Data Processing/BLAISE TO BLAISE.msu"

However, I cannot simulate this behavior in Python-- no matter what I use. I have tried os.system and subprocess.call and subprocess.Popen

If I run something like the following

p= subprocess.Popen("C:/Flow Check/Run Quick/Applications/Manipula.exe" "C:/Flow Check/Data Processing/BLAISE TO BLAISE.msu", stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
 print line,
retval = p.wait()

I get an error: The System Cannot Find the File Specified. I've triple-checked, the file is clearly there because it works when I run the commandline.

When I add shell=True to subprocess.Popen a new error appears that there is no directory C:/Flow, I think because the shell has a hard time processing spaces... I just don't know what's going on.

When I do os.system("C:/Flow Check/Run Quick/Applications/Manipula.exe" "C:/Flow Check/Data Processing/BLAISE TO BLAISE.msu") nothing happens.

Any ideas?

like image 659
Parseltongue Avatar asked Dec 20 '22 21:12

Parseltongue


1 Answers

Specify program and its arguments as list:

p = subprocess.Popen([
    "C:/Flow Check/Run Quick/Applications/Manipula.exe",
    "C:/Flow Check/Data Processing/BLAISE TO BLAISE.msu"],
    stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

Writing string literals serially merges the strings:

>>> "abc" "xyz"
'abcxyz'
like image 126
falsetru Avatar answered Jan 25 '23 23:01

falsetru