Question

I'm trying to use python to run a program.

from subprocess import Popen 
sa_proc = Popen(['C:\\sa\\sa.exe','--?'])

Running this small snippit gives the error:

WindowsError: [Error 2] The system cannot find the file specified

The program exists and I have copy and pasted directly from explorer the absolute path to the exe. I have tried other things and have found that if I put the EXE in the source folder with the python script and use './sa.exe' then it works. The only thing I can think of is that I'm running the python script (and python) from a separate partition (F:).

Any ideas? Thanks

Was it helpful?

Solution

As the docs say, "On Windows: the Popen class uses CreateProcess() to execute the child program, which operates on strings. If args is a sequence, it will be converted to a string using the list2cmdline() method.". Maybe that method is messing things up, so why not try the simpler approach of:

sa_proc = Popen('C:\\sa\\sa.exe --?')

If this still fails, then: what's os.environ['COMSPEC'] just before you try this? What happens if you add , shell=True to Popen's arguments?

Edit: turns out apparently to be a case of simple mis-spellling, as 'sa' was actually the program spelled SpamAssassin -- double s twice -- and what the OP was writing was spamassasin -- one double s but a single one the second time.

OTHER TIPS

You may not have permission to execute C:\sa\sa.exe. Have you tried running the program manually?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top