简体   繁体   中英

How are arguments resolved when executing a file using subprocess.call in Python?

I would like to execute an .exe file from a Python script, on Windows, with a bunch of arguments. Part of those arguments are the paths to input files and outputs.

My question: can I save the paths in a variable, which I then use as an argument, or does the call take only the name of the argument instead of its value?

My idea:

outputPath = C:\...\folder1\folder2
inputpath = D:\...\folder1\folder2
subprocess.call('runnable.exe', outputPath, inputPath)

instead of

subprocess.call('runnable.exe', C:\...\folder1\folder2, D:\...\folder1\folder2)

The call function, like every other function and method in Python, takes variables or literals as arguments. See What is the difference between literal and variables in Python? for more details on those. You may also consider reading through the Python tutorial . It can give you a great introduction to programing in Python.

you can do something like this

from subprocess import Popen
outputPath ='C:\...\folder1\folder2'
inputpath = 'D:\...\folder1\folder2'
command='ruunable.exe' + outputPath + inputpath
proc=Popen(command)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM