how to run an exe file with the arguments using python
You can also use subprocess.call()
if you want. For example,
import subprocessFNULL = open(os.devnull, 'w') #use this if you want to suppress output to stdout from the subprocessfilename = "my_file.dat"args = "RegressionSystem.exe -config " + filenamesubprocess.call(args, stdout=FNULL, stderr=FNULL, shell=False)
The difference between call
and Popen
is basically that call
is blocking while Popen
is not, with Popen
providing more general functionality. Usually call
is fine for most purposes, it is essentially a convenient form of Popen
. You can read more at this question.
The accepted answer is outdated. For anyone else finding this you can now use subprocess.run()
. Here is an example:
import subprocesssubprocess.run(["RegressionSystem.exe", "-config filename"])
The arguments can also be sent as a string instead, but you'll need to set shell=True
. The official documentation can be found here.
os.system("/path/to/exe/RegressionSystem.exe -config "+str(config)+" filename")
Should work.