在调用子进程“ WindowsError:[错误2]系统找不到指定的文件”时

时间:2018-12-29 08:39:23

标签: python python-2.7 subprocess

我希望将输出保存在变量中。

from subprocess import check_output

output = check_output("swetest -edir -b03.01.1997 -ut021:20:00 -p01425367m -house9.1266304,88.6578489,a -sid1 -fPl -g, "
                      "-head").split(",")

print output

当我在python终端中逐行执行此代码时,它可以正常工作

from subprocess import check_output 
output = check_output("swetest -edir -b03.01.1997 -ut021:20:00 -p01425367m -house9.1266304,88.6578489,a -sid1 -fPl -g, -head").split(",")
output[0] 
"SUN"

但是,在pycharm中,此程序引发错误。

Traceback (most recent call last):
  File "C:/Users/Gman Aravindh/PycharmProjects/trail_project/test.py", line 3, in <module>
    output = check_output("swetest -edir -b03.01.1997 -ut021:20:00 -p01425367m -house9.1266304,88.6578489,a -sid1 -fPl -g, "
  File "C:\Python27\lib\subprocess.py", line 212, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "C:\Python27\lib\subprocess.py", line 390, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

pycharm如何识别路径?我尝试了其他堆栈溢出解决方案,请给我一些建议。我也在环境变量中添加了最swetest。它可以在python终端中运行,但不能在pycharm中运行

0 个答案:

没有答案