Error of running an executable file from Python subprosess

旧时模样 提交于 2019-12-14 02:24:47

问题


I am trying to run an executable file (a linear programming solver CLP.exe) from Python 3.5.

 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)

When I run the python file in Eclipse PyDev, I can see the results in Eclipse console.

But, no solution results are saved at the file of "solutionFile.txt".

In the Eclipse console, I got:

  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

When I run the command in MS windows shell from command line:

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

I can get results in the solution file. And, the bold lines do not appear in the output if I run the command in the command line.

Why the solition.txt file was not created and no solutions results were saved to it if I run the command from Python subprocess ?


回答1:


Every space separated token needs to be another argument in the array for 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)


来源:https://stackoverflow.com/questions/38928330/error-of-running-an-executable-file-from-python-subprosess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!