【发布时间】:2014-09-03 23:31:53
【问题描述】:
我有一个简单的 Python 脚本:
log("Running command: " + str(cmd))
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE, close_fds=close_fds)
我在 Windows 上的相同 python 版本 2.6.1 上执行它,但在不同的虚拟机上。一个是 Windows Server 2008 Enterprise,第二个是 Windows Server Enterprise,我在 only 其中一个上遇到错误。
来自 Windows Server Enterprise 的日志:
Running command: C:\Program File\MyProgram\program.exe "parameters"
Error: 'C:\\Program' is not recognized as an internal or external command
来自 Windows Server 2008 Enterprise 的日志:
Running command: C:\Program File\MyProgram\program.exe "parameters"
...
该错误仅发生在一种环境中。我知道应该对路径进行转义,但是subprocess.Popen 怎么可能处理带有空格而不转义的路径?
【问题讨论】:
-
cmd是字符串还是字符串列表?
-
@beroe 类似,但不一样。就我而言,我只有一个工作方式不同的代码,有时它可以处理带有空格的路径,有时不能,我试图理解为什么。
-
@tdelaney 它是一个字符串
-
错误的回溯是什么?
标签: python createprocess