Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Suppose I have a file RegressionSystem.exe. I want to execute this executable with a -config argument. The commandline should be like:

RegressionSystem.exe -config filename

I have tried like:

regression_exe_path = os.path.join(get_path_for_regression,'Debug','RegressionSystem.exe')
config = os.path.join(get_path_for_regression,'config.ini')
subprocess.Popen(args=[regression_exe_path,'-config', config])

but it didn't work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
460 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can also use subprocess.call() if you want. For example,

import subprocess
FNULL = open(os.devnull, 'w')    #use this if you want to suppress output to stdout from the subprocess
filename = "my_file.dat"
args = "RegressionSystem.exe -config " + filename
subprocess.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...