Popen错误:[Errno 2]没有这样的文件或目录

Popen错误:[Errno 2]没有这样的文件或目录

问题描述:

我有一些自定义命令.

# works 
subprocess.Popen(['python'], stdout=subprocess.PIPE)

但是,如果我有自己的系统命令,例如deactivate,则会收到该错误

But if I have my own system commands like deactivate, I get that error

Traceback (most recent call last):
  File "runner2.py", line 21, in <module>
    main() 
  File "runner2.py", line 18, in main
    subprocess.Popen(['deactivate',], stdout=subprocess.PIPE)
  File "/usr/lib/python2.6/subprocess.py", line 633, in __init__
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

更不用说我需要在我的沙箱virtualenv下执行此操作了.

Let alone I need to execute this under my sandbox virtualenv.

尝试在Popen调用中添加一个额外的参数'shell = True'.

Try add an extra parameter 'shell=True' to the Popen call.