来自 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 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 windows shell 中从命令行 运行 命令时:
C:\MyPath\clp.exe C:\Temp\LpModel.mps -max -dualSimplex -printi all -solution C:\Temp\solution.txt
我可以在解决方案文件中得到结果。而且,如果我在命令行中 运行 命令,粗体行不会出现在输出中。
如果我 运行 来自 Python 子进程的命令,为什么没有创建 solition.txt 文件并且没有解决方案结果保存到其中?
每个 space 分隔的标记都需要是 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)
我正在尝试 运行 来自 Python 3.5 的可执行文件(线性规划求解器 CLP.exe)。
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 windows shell 中从命令行 运行 命令时:
C:\MyPath\clp.exe C:\Temp\LpModel.mps -max -dualSimplex -printi all -solution C:\Temp\solution.txt
我可以在解决方案文件中得到结果。而且,如果我在命令行中 运行 命令,粗体行不会出现在输出中。
如果我 运行 来自 Python 子进程的命令,为什么没有创建 solition.txt 文件并且没有解决方案结果保存到其中?
每个 space 分隔的标记都需要是 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)