我想在程序名和参数中逃避’“’和所有其他野性字符,所以我尝试双引号.我可以在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']
谢谢!