0

I am trying to run an external executable, that requires complex parameters and capture the output in a variable. How do I do this?

import os
import subprocess
subprocess.call('C:\\bin\\test.exe', ' -b10.10.2000',' -house50.20E,10.40N',' -hsyE',' -utc00.18',' -eswe',' -sid27',' -fPls',' -head',' -g')


>>> subprocess.call('C:\\bin\\test.exe', ' -b10.10.2000',' -house50.20E,10.40N',' -hsyE',' -utc00.18',' -eswe',' -sid27',' -fPls',' -head',' -g')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 3
25, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 7
29, in __init__
    raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
>>>

thanks

2
  • Okay, cool. So what's the problem? In what way does the code you shared not work? Please read How to Ask. Commented Apr 20, 2019 at 1:40
  • @Chris It throws an error. Commented Apr 20, 2019 at 1:41

1 Answer 1

2

The output is the stdout of the other process?

You can use subprocess.Popen and communicate() then:

 proc = subprocess.Popen( [ 'C:\\bin\\test.exe', '-b10.10.2000','-house50.20E,10.40N','-hsyE','-utc00.18','-eswe','-sid27','-fPls','-head','-g' ], stdout = subprocess.PIPE, stderr = subprocess.PIPE )
 out, err = proc.communicate() #out -> stdout, err -> stderr
Sign up to request clarification or add additional context in comments.

10 Comments

I added the error message. I will try your suggestion.
The reason for the error message is that your call to "call" is wrong. The first parameter should be a list: [ executable, parameter1, parameter2 ].
Now says illegal option -b10.10.2000
Who says that? Doesn't sound like an python subprocess error to me? Maybe the parameters for the other executable itself are wrong?
Fixed that, it didnt like the space in the parameters.
|

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.