1

I am writing a small python script where I open an existing executable (.exe) and I send a string as an argument.

I am using the subprocess.call method and I get the following error:

File "C:\Python34\lib\subprocess.py", line 537, in call
   with Popen(*popenargs, **kwargs) as p:
File "C:\Python34\lib\subprocess.py", line 767, in __init__
   raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

My code

import os
import subprocess

x = subprocess.call("C:\\Users\\Desktop\\Program\\Program.exe", y)

where y is a string I am passing.

I am trying to upgrade an old VB code. The original code calls the executable and passes an argument as shown below. I am trying to replicate this in Python.

Private comm As ExecCmd
Dim cmd As String
Dim app As String
Dim e As New ExecCmd

exec_1= "...\Desktop\Program.exe"
x = "Text" & Variable & " Hello" & Variable2

comm.StartApp exec_1, x   'starts the .exe file with an argument

2 Answers 2

4

Put the program and any arguments you want into an array first.

import os
import subprocess

x = subprocess.call(["C:\\Users\\Desktop\\Program\\Program.exe", y])
Sign up to request clarification or add additional context in comments.

Comments

3

The command and arguments should be in a list

x = subprocess.call(["C:\\Users\\Desktop\\Program\\Program.exe", y])

Documentation

4 Comments

Thank you for the explanation. I placed all the arguments in a list and it worked.
Do you happen to know how can I read the output of the executable? I tried this and I get an error: x = subprocess.Popen(["C:\\Users\\Desktop\\Program\\Program.exe", y], stdout=PIPE) where PIPE is not defined.
Read the docs. PIPE is an attribute of the subprocess module, use stdout=subprocess.PIPE But if you need pipes you should be using the popen class or subprocess.check_output
Thanks, it works. This what I did: subprocess.check_output(["C:\\Users\\Desktop\\Program\\Program.exe", y]). The output is then converted to a string by using the .decode()

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.