python中的子进程调用错误

时间:2014-08-06 21:57:39

标签: python subprocess call

我遇到了子进程调用问题。

我编写了一个非常简单的代码(test.py),只需打印" Hello ... .."

然后我做了以下事情:

/sw/bin/python2.7
import subprocess
call (["test.py"])

我收到以下错误:

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/sw/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
    File "/sw/lib/python2.7/subprocess.py", line 709, in __init__
    errread, errwrite)
    File "/sw/lib/python2.7/subprocess.py", line 1326, in _execute_child
    raise child_exception
    OSError: [Errno 2] No such file or directory

我可以使用os.system,但我很想学习这个子进程方法。 我哪里错了?

被调用的test.py位于同一个文件夹中。

1 个答案:

答案 0 :(得分:2)

试试这个:

subprocess.call(["python", "test.py"])