views:

466

answers:

2

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

A: 

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

Mark Roddy
Program runs when manually executed. This user account has admin rights and was the same user that created the exe I am attempting to run.
+2  A: 

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.

Alex Martelli
Converting it back to just a regular string as you suggested didn't work. os.environ['COMSPEC'] = C:\WINDOWS\system32\cmd.exe and Popen('C:\\spamassasin\\spamassasin.exe --?', shell=True) Outputs: 'C:\spamassasin\spamassasin.exe' is not recognized as an internal or external command, operable program or batch file.
It's spelled SpamAssassin -- double s twice -- and what you're writing is spamassasin -- one double s but a single one the second time. Editing my answer accordingly.
Alex Martelli
It appears to have been a typo issue after all, which is weird since I copy/pasted directory and filename prior to this, and it still hadn't worked. Thanks!