我正在尝试执行一个程序,该程序可用于我的命令提示符,但不在Python中。
命令提示符:
C:\Users\Documents\libexe\tfc\bin\Debug>asc-dir
asc-dir.: directory not linked to an ASC directory //Expected output
测试脚本:
proc = subprocess.Popen('asc-dir', stdout=subprocess.PIPE)
(result, err) = proc.communicate()
print(result)
错误:
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 . . .
答案 0 :(得分:1)
您似乎正在运行某些Visual Studio扩展。也许它摆弄了传递给python的PATH env var?因此,您可能需要指定绝对路径。
import os
print os.environ['PATH']
答案 1 :(得分:1)
看起来我需要设置shell=True
proc = subprocess.Popen('asc-dir', stdout=subprocess.PIPE, shell=True)
(result, err) = proc.communicate()