I need to run an application (binary file) and pass arguments using a Python code. Some arguments represent strings got during Python file processing.
for i in range ( len ( files ) ) :
subprocess.call(["test.exe", files[i]]) //How to pass the argument files[i]
Thanks...
Updated question:
Maybe I do not understand passing arguments in Python 3. A code without parameters runs OK
args = ['test. exe']
subprocess.call(args)
However the code with parameter causes an error:
args = ['test. exe']
subprocess.call(args, '-f') //Error
Error:
Error File "C:\Python32\lib\subprocess.py", line 467, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python32\lib\subprocess.py", line 652, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
Information can be passed into functions as arguments. Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma.
args = ['test. exe']
subprocess.call(args, '-f') #gives Error
should be:
args = ['test.exe', '-f']
subprocess.call(args)
The command line argument should all be inside a single list for the first parameter of subprocess.call. The second argument to call is bufsize, which is supposed to be an integer (that's why you get that particular error)
With regard to your updated question: The arguments for your subprocess are not passed as individual parameters to call(); rather, they're passed as a single list of strings, like so:
args = ["test.exe", "first_argument", "second_argument"]
Original response: The code as you have it will create a separate process for each element in files. If that's what you want, your code should work. If you want to call the program with all of the files simultaneously, you'll want to concatenate your list:
args = ["test.exe"] + files
subprocess.call(args)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With