2016-08-13 2 views
1

Ich versuche, eine ausführbare Datei (ein linearer Programmierlöser CLP.exe) aus Python 3.5 ausführen.Fehler beim Ausführen einer ausführbaren Datei von Python-Subprocess

Wenn ich die Python-Datei in Eclipse PyDev ausführen, kann ich die Ergebnisse in der Eclipse-Konsole sehen.

Es werden jedoch keine Lösungsergebnisse in der Datei "solutionFile.txt" gespeichert.

In der Eclipse-Konsole, ich habe:

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 

Wenn ich den Befehl in MS Windows-Shell von der Kommandozeile:

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

I Ergebnisse in der Lösungsdatei erhalten. Und die fett gedruckten Zeilen erscheinen nicht in der Ausgabe, wenn ich den Befehl in der Befehlszeile ausführe.

Warum wurde die Datei solition.txt nicht erstellt und es wurden keine Lösungsergebnisse gespeichert, wenn ich den Befehl vom Python-Subprozess aus führe?

Antwort

1

Jeder Raum getrennt Token ein anderes Argument in dem Array sein muss für 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) 
Verwandte Themen