2016-08-13 14 views
1

Python 3.5から実行可能ファイル(線形プログラミングソルバーCLP.exe)を実行しようとしています。 Pythonサブプロスから実行可能ファイルを実行する際のエラー

Import subprocess 

exeFile = " C:\\MyPath\\CLP.exe" 
arg1 = "C:\\Temp\\LpModel.mps" 
arg2 = "-max" 
arg3 = " -dualSimplex" 
arg4 = " -printi all" 
arg5 = "-solution t solutionFile.txt" 
subprocess.check_output([exeFile, arg1, arg2, arg3, arg4, arg5], stderr=subprocess.STDOUT, shell=False) 

私はEclipseのPyDevは内のpythonファイルを実行

は、私は、Eclipseのコンソールに結果を見ることができます。

ただし、解決結果は "solutionFile.txt"ファイルに保存されません。 Eclipseのコンソールで

、私が得た:

b'Coin LP version 1.16, build Dec 25 2015 
    command line - C:\\MyPath\\clp.exe C:\\Temp\\LpModel.mps -max  -dualSimplex -printi all -solution C:\\Temp\\solution.txt 

At line 1 NAME   ClpDefau 
At line 2 ROWS 
At line 5 COLUMNS 
At line 8 RHS 
At line 10 BOUNDS 
At line 13 ENDATA 
Problem ClpDefau has 1 rows, 2 columns and 2 elements 
Model was imported from C:\\Temp\\LpModel.mps in 0.001 seconds 
No match for -max - ? for list of commands 
No match for -dualSimplex - ? for list of commands 
No match for -printi all - ? for list of commands 
No match for -solution C:\\Temp\\solution.txt - ? for list of commands 
Presolve 0 (-1) rows, 0 (-2) columns and 0 (-2) elements 
Empty problem - 0 rows, 0 columns and 0 elements 
Optimal - objective value 4 
After Postsolve, objective 4, infeasibilities - dual 0 (0), primal 0 (0) 
Optimal objective 4 - 0 iterations time 0.002, Presolve 0.00 

私はMSウィンドウでコマンドを実行し、コマンドラインからシェル:

C:\\MyPath\\clp.exe C:\\Temp\\LpModel.mps -max -dualSimplex -printi all -solution C:\\Temp\\solution.txt 

私はソリューションファイルに結果を得ることができます。コマンドラインでコマンドを実行すると、太字の行は出力に表示されません。

なぜ私はPythonのサブプロセスからコマンドを実行するとsolit.txtファイルが作成されず、ソリューション結果が保存されませんでしたか?

答えて

1

すべてのスペースで区切られたトークンはsubprocess.check_output

exeFile = " C:\\MyPath\\CLP.exe" 
subprocess.check_output([ 
    exeFile, 
    "C:\\Temp\\LpModel.mps", 
    "-max", 
    "-dualSimplex", 
    "-printi", 
    "all", 
    "-solution", 
    "t", 
    "solutionFile.txt"], 
    stderr=subprocess.STDOUT, 
    shell=False) 
のために、アレイ内の別の引数にする必要があります
関連する問題