我正在尝试调用名称中包含括号的可执行文件(例如'test(1).exe'
)。
使用Python 3.6.2,当我尝试以下操作时:
os.system('test(1).exe')
我明白了:
'test' is not recognized as an internal or external command, operable
program or batch file.
但是如果我通过删除'test1).exe'
将文件名更改为'('
,那么以下工作成功:
os.system('test1).exe')
左括号导致os.system
问题的任何想法?
在没有subprocess.call()
的情况下使用shell=True
可以避免以shell安全的方式引用参数:
subprocess.call(["test(1).exe"])
解决方案:在'(''前面放一个'^'字符:
os.system('test^(1).exe')