子进程不能正常工作



我有这段代码,我需要运行一个子进程并打印命令窗口中的输出。

import subprocess
msprompt = 'C:WindowsMicrosoft.NETFramework64\v4.0.30319\MSBuild.exe'
path = "C:/Users/bgb/Documents/Brent/Code/Visual Studio/tree.DataManagement.UnitTests./tree.DataManagement.UnitTests.vbproj"
def command(msprompt, openFile):
    for line in finalPathList:

        p = subprocess.Popen([msprompt, path], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        for line in p.stdout.readlines():
            print line,
        retval = p.wait()

当我在编译器中运行这个时,它不起作用,它吐出这样的消息:

MSBUILD : error MSB1009: Project file does not exist.
Switch: "C:/Users/bgb/Documents/Brent/Code/Visual Studio/tree.FormControls.UnitTests./tree.FormControls.UnitTests.vbproj"

然而,如果我完全分开打开命令窗口,我复制并粘贴msprompt,然后我复制path并将其粘贴到命令窗口并按enter键,它工作得很好,有人知道我在command函数中搞砸了什么吗?

非常感谢帮助!

我认为你的路径格式是不正确的,它应该有两个反斜杠\,而不是正斜杠/

为了调试,尝试使用os.path.exists(path),首先确保路径是正确的。然后你可以使用os.path.join来修复你的路径(文档在这里)。

最新更新