2

我正在调整我在 Linux 上为 Win 7 编写的代码。

在 Linux 上是:

subprocess.call(['./myscript.py', arg1, arg2, arg3])

它是从 Shell 启动的,一切正常。对于 Windows(我使用 Idle 中的 Python),我做到了:

subprocess.call(['myscript.py', arg1, arg2, arg3],  shell=True)

它似乎没有启动任何东西,但没有给我任何错误。我尝试使用 pdb.set_trace() 调试该函数,而 myscript.py 中的检查点没有显示出来。

4

1 回答 1

1

As in the comments and the linked question, in Windows you cannot simply execute the python script, you also need to provide the path to the python executable. As you're already using python, you can find the location of the executable simply with sys.executable

import sys

p = subprocess.Popen([sys.executable, 'myscript.py', arg1, arg2, arg3])

The output is being piped to stderr and stdout - to see it you'll also need communicate

(stdoutdata, stderrdata) = p.communicate()

print stdoutdata, 
print stderrdata
于 2013-03-21T15:31:16.180 回答