我是Python的初学者。我想运行一个包含许多参数的exe文件。一些参数是文件的路径,有些只是字符串。 exe的路径中也有空格。我可以通过命令提示符运行它,如下所示。
C:\Program Files (x86)\XXX 8.0\bin\xxx.exe -I -c "E:\files" -m ASCII -lib "" -i "E:\Trialtest\input.txt" -t "E:\test\output.txt" -s "E:\Trialtest\test\output.struct"
我试了很多帖子没什么用。我找到了一个与我的查询类似的帖子。但对我来说没有用。请帮我用Python运行。
我试过的代码是
subprocess.check_output(["C:\Program Files (x86)\xxx_x\yyy 8.0\bin\abc.exe", "-I", "-c", "E:\Trialtest.gtp", "-m", "ASCII ", "-lib", "", "-i", "E:\Trialtest\input.txt", "-t", "E:\Trialtest\test\output.txt", "-s", "E:\Trialtest\test\output.struct"])
错误是
Traceback (most recent call last):
File "<pyshell#73>", line 1, in <module>
subprocess.check_output(["C:\Program Files (x86)\xxx_x\yyy 8.0\bin\abc.exe", "-I", "-c", "E:\Trialtest.gtp", "-m", "ASCII ", "-lib", "", "-i", "E:\Trialtest\input.txt", "-t", "E:\Trialtest\test\output.txt", "-s", "E:\Trialtest\test\output.struct"])
File "C:\Python27\lib\subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
感谢。
答案 0 :(得分:1)
您所要做的就是使用子流程
subprocess.check_output(["C:\Program Files (x86)\XXX 8.0\bin\xxx.exe", "-I", "-c", "E:\files", "-m", "ASCII", "-lib","" ,"-i", "E:\Trialtest\input.txt" ,"-t" ,"E:\test\output.txt", "-s", "E:\Trialtest\test\output.struct"])