0
votes
import subprocess

subprocess.call(['C:\Windows\System32\notepad.exe'])

Leads to error:

Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 5.0\src\debug\tserver_sandbox.py", line 3, in pass File "c:\Python27\Lib\subprocess.py", line 172, in call return Popen(*popenargs, **kwargs).wait() File "c:\Python27\Lib\subprocess.py", line 408, in init errread, errwrite) File "c:\Python27\Lib\subprocess.py", line 663, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified

But I can run Notepad using that exact path from the filename bar of a folder window. What am I missing?

2
That string contains a newline character in the middle! Specify it as a raw string: r'C:\...' so that backslashes aren't given any special meaning. - jasonharper
Just use 'notepad' as cmd and 'shell=True' - crissal

2 Answers

3
votes

The problem is the unescaped backlashes in your path. Python interprets '\n' as a single newline character.

Either escape the backslashes:

'C:\\Windows\\System32\\notepad.exe'

Or (preferred) use a raw string with an r prefix:

r'C:\Windows\System32\notepad.exe'
0
votes

Here's the code that might work for you subprocess.Popen(['C:\\Windows\\System32\\notepad.exe'])