2013-04-10 78 views
8

ファイルがあるとします。RegressionSystem.exeです。この実行ファイルを-config引数で実行したいと思います。コマンドラインは次のようにする必要があります。pythonを使って引数を指定してexeファイルを実行する方法

RegressionSystem.exe -config filename 

私は次のように試してみました:

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]) 

が、それはうまくいきませんでした。

+3

どのように動作しませんでしたか?エラーメッセージとは何ですか? –

答えて

2
os.system("/path/to/exe/RegressionSystem.exe -config "+str(config)+" filename") 

10

必要に応じてsubprocess.call()を使用することもできます。例えば、

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) 

callPopenの違いはPopenはないがcallは、より一般的な機能を提供Popenと、ブロックされている基本的ことです。通常callはほとんどの目的には問題ありませんが、本質的にはPopenという便利な形式です。 this questionで詳しく読むことができます。

関連する問題