简体   繁体   中英

Python script to run an exe file with multiple parameters

I am a beginner in Python. I wanted to run an exe file with a number of parameters to be passed. The some parameters are path to files and some are just strings. The path for the exe also has spaces in it. I could run it via command prompt as below.

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"

I tried a lot of posts nothing worked. I found one post which is similar to my query. But didnt work for me. Please help me run this using Python.

The code i tried is

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"])

the error is

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

Thanks.

您所要做的就是使用子流程

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"])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM