gpt4 book ai didi

python - Popen 找不到命令行上可用的批处理文件

转载 作者:行者123 更新时间:2023-12-01 05:06:30 25 4
gpt4 key购买 nike

我正在尝试执行一个可在命令提示符下使用但不在 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 . . .

最佳答案

您似乎正在运行某些 Visual Studio 扩展。也许它会破坏传递给 python 的 PATH 环境变量?因此,您可能需要指定绝对路径。

import os
print os.environ['PATH']

关于python - Popen 找不到命令行上可用的批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24906734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com