2

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.

5
  • Use subprocess module Commented Oct 27, 2015 at 13:33
  • Tried that too. But getting errors. Commented Oct 27, 2015 at 13:35
  • 1
    @SaravanaMurthy Add that to your post. Both the code AND the traceback. Commented Oct 27, 2015 at 13:35
  • subprocess is perfect you just have to pass param correctly, checking escape and all. Commented Oct 27, 2015 at 13:37
  • Maybe you'll want to try os.popen(your_command).read() ? Commented Oct 27, 2015 at 13:45

1 Answer 1

1

All you have to do is to use subprocess

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"])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.