Reputation: 3189
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
Upvotes: 0
Views: 100
Reputation: 539
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
Upvotes: 2