如果我有以下脚本:
import os;
os.system("C:\\Temp\\a b c\\Notepad.exe");
raw_input();
然后失败,出现以下错误:
'C:\Temp\a' is not recognized as an internal or external command, operable program or batch file.
如果我逃脱引号的程序:
import os;
os.system('"C:\\Temp\\a b c\\Notepad.exe"');
raw_input();
然后作品。不过,如果我添加了一个参数,它再次停止工作:
import os;
os.system('"C:\\Temp\\a b c\\Notepad.exe" "C:\\test.txt"');
raw_input();
什么是执行程序,并等待其完成正确的方法是什么?我不需要读取它的输出,因为它是一个可视化程序,可以完成一项工作然后退出,但我需要等待它完成。
另请注意,将程序移动到非间隔路径也不是一个选项。
这不起作用或者:
import os;
os.system("'C:\\Temp\\a b c\\Notepad.exe'");
raw_input();
注意换单/双引号。
带或不带参数在这里记事本,它失败,出现错误消息
The filename, directory name, or volume label syntax is incorrect.
+0
使用此:`操作系统。系统(r'C:\ temp \“abc”\ Notepad.exe')` 或者这个:`os.system('C:\\ temp \\“abc”\\ Notepad.exe')` –
2016-08-11 07:15:02