我想在程序名称和参数中转义 '"' 和所有其他通配符,所以我尝试将它们双引号。我可以在 cmd.exe 中执行此操作
C:\bay\test\go>"test.py" "a" "b" "c"
hello
['C:\\bay\\test\\go\\test.py', 'a', 'b', 'c']
但是使用 os.sytem 的以下代码有什么问题?
cmd = '"test.py" "a" "b" "c"'
print cmd
os.system(cmd)
它的输出:
C:\bay\test\go>test2.py
"test.py" "a" "b" "c"
'test.py" "a" "b" "c' is not recognized as an internal or external command,
operable program or batch file.
为什么整个字符串 '"test.py" "a" "b" "c"' 被识别为单个命令?但下面的例子不是:
cmd = 'test.py a b c'
print cmd
os.system(cmd)
C:\bay\test\go>test2.py
test.py a b c
hello
['C:\\bay\\test\\go\\test.py', 'a', 'b', 'c']
谢谢!