4

Python 2.7 - crashing on subprocess.py - Windows Error: [Error 2] The system cannot find file

File "C:\Python27\lib\subprocess.py", line 709, in __init__
    errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

I have searched the rest of the questions and tried all the path settings and environmental variables and all that seems fine.

Thanks for your help in advance.

Denim Datta
  • 3,740
  • 3
  • 27
  • 53
Freekstile
  • 51
  • 1
  • 4

2 Answers2

0

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

I had the same error when I want to envoke a programm which isn't installed (I use ubuntu instead of windows).

http://docs.python.org/2/library/subprocess.html#exceptions

try to excute the command manually in the shell , to get the real error

or use this fine method :

from subprocess import CalledProcessError, check_output

try:
    output = check_output(["ls", "non existent"])
except CalledProcessError as e:
    print(e.returncode)

N.B: in my system (ubuntu) , I get :

ls: cannot access non existent: No such file or directory 2

In windows there is no "ls" command , you will get exception meaning that.

from : Check a command's return code when subprocess raises a CalledProcessError exception

check this : Using subprocess to run Python script on Windows

Community
  • 1
  • 1
tabebqena
  • 1,204
  • 1
  • 13
  • 23
0

Use list while running command via subproccess. list should be created by follows: Suppose you want ot run command :

ls -l

Then command should be

cmd = ["ls" "-l" ]
subprocess.Popen(cmd)
user3273866
  • 594
  • 4
  • 8