在Python中运行命令

时间:2011-04-13 17:23:40

标签: python command

我是python的新手。任何想法为什么这不起作用:


C:\Python27>python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> cmdBuilder = os.path.join("C:\\","Program Files","InstallShield","2011 SAB",
"System","IsCmdBld.exe")
>>> os.system(cmdBuilder)
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
1
>>>

可执行文件确实存在。它似乎陷入了程序和文件之间的空间

由于

2 个答案:

答案 0 :(得分:3)

尝试用引号括起可执行文件:

>>> os.system('"'+cmdBuilder+'"')

答案 1 :(得分:1)

因为路径的某些部分包含空格。

另见

http://help.wugnet.com/windows2/Program-space-batch-file-ftopict489742.html

相关问题