Reputation: 6968
I'm trying to execute a program which is available to my command prompt but isn't in Python.
Command prompt:
C:\Users\Documents\libexe\tfc\bin\Debug>asc-dir
asc-dir.: directory not linked to an ASC directory //Expected output
Test Script:
proc = subprocess.Popen('asc-dir', stdout=subprocess.PIPE)
(result, err) = proc.communicate()
print(result)
Error:
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensio
ns\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 1
06, in exec_file
exec_code(code, file, global_variables)
File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensio
ns\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 8
2, in exec_code
exec(code_obj, global_variables)
File "C:\Users\mryan.\git\web\PBNBApi\pbnb_cli\test.py", lin
e 9, in <module>
proc = subprocess.Popen('asc-dir', stdout=subprocess.PIPE)
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
Press any key to continue . . .
Upvotes: 1
Views: 747
Reputation: 6968
Looks like I needed to set shell=True
proc = subprocess.Popen('asc-dir', stdout=subprocess.PIPE, shell=True)
(result, err) = proc.communicate()
Upvotes: 1
Reputation: 3302
You seem to be running through some Visual Studio extension. Maybe it fiddles with the PATH env var passed to python? As such, you may need to specify the absolute path.
import os
print os.environ['PATH']
Upvotes: 1