double quote escaping in os.system on windows

只愿长相守 提交于 2019-11-29 11:56:18
YOU

Try with os.system('python "test.py" "a" "b" "c"')

You can also use subprocess module for that kind of purpose,

please take a look this thread

UPDATE:When I do, os.system('"test.py" "a" "b" "c"'), I got similar errors, but not on os.system('test.py "a" "b" "c"'), So, I like to assume that first parameter should not be double-quoted

Furthing google comes this page

http://ss64.com/nt/syntax-esc.html

To launch a batch script which itself requires "quotes" 
CMD /k ""c:\batch files\test.cmd" "Parameter 1 with space" "Parameter2 with space"" 

cmd = '""test.py" "a" "b" "c""' does work!

Actually, it just work as design. You can NOT use os.system like that. See this: http://mail.python.org/pipermail/python-bugs-list/2000-July/000946.html

user2435152

Enclose the arguments in brackets, it works.

CMD /k ("c:\batch files\test.cmd" "Parameter 1 with space" "Parameter2 with space")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!