我想使用 Popen 执行命令,请参见下面的代码:
import subprocess
p = subprocess.Popen('/usr/bin/python a.py')
p2 = subprocess.Popen('ls', stdout = subprocess.PIPE)
print p2.stdout.readlines()
当我执行此脚本时,我收到以下错误:
File "demo.py", line 4, in <module>
p0 = subprocess.Popen('/usr/bin/python a.py')
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
有什么问题?另一个问题是,如果 a.py 是一个“while-True-loop”,p2 可以返回吗?
谢谢!