2016-08-17 5 views
0

この質問は前の質問に関連しています。Pythonサブプロセスから実行可能ファイルを実行してログ結果がファイルにダンプされないエラー

Error of running an executable file from Python subprosess

私は、Python 3.5から実行ファイル(線形計画ソルバーCLP.exe)を実行しようとしています。

Import subprocess 

exeFile = "C:\\MyPath\\CLP.exe" 
arg1 = "C:\\Temp\\LpModel.mps" 
arg2 = "-max" 
arg3 = "-dualSimplex" 
arg4 = "-printi" 
arg4a = "all" 
arg5 = "-solution" 
arg6 = "solutionFile.txt" 
arg7 = "-log" 
arg8 = "6" 
arg9 = ">" 
arg10 = "log.txt" 
subprocess.check_output([exeFile, arg1, arg2, arg3, arg4a, arg5,arg6, arg7, arg8, arg9, arg10], stderr=subprocess.STDOUT, shell=False) 

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

は、私は、Eclipseのコンソールに結果を見ることができるとソリューションの結果も「solution.txt」に保存されます。

ただし、ログ結果は "log.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\\solutionFile.txt > log.txt 

    Optimal - objective value 118816.5 
    Optimal objective 110 - 40 iterations time 0.022 
    logLevel was changed from 1 to 6 
    No match for > - ? for list of commands 
    No match for log.txt - ? for list of commands 

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

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

私はlog.txtとで結果をログ取得することができます。

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

答えて

0

デフォルトのstdout記述子をあなたのログファイル記述子で置き換えることができます。私はエラーを得た。この

with open('log.txt', 'w+') s fid: 
    subprocess.check_call([arg1,...,arg8],stdout = fid, stderr=subprocess.STDOUT, shell = False) 
+0

をお試しください:ValueErrorを上げる(「許可されていない標準出力引数を、それが上書きされます」)とValueError:許可されていない標準出力引数、それが上書きされます。 – usa

+0

これは保証できませんが、check_outputの代わりにsubprocess.check_callを試すことができます –

関連する問題