0

I need to call an executable program with Python, let's say:

C:\Program Files\ANSYS Inc\v140\ansys\bin\winx64\ANSYS140.exe

I would need to have a txt file (afshin.txt) run with this executable application and then get the output file which is a txt file as well. In MATLAB for example it would be:

dos '"C:\Program Files\Ansys Inc\v121\ANSYS\bin\intel\ansys121.exe" -p AA_T_A -b -i afshin.txt -o file01.out' 
mod_1 = load('output_res.txt');

Would you help me to do it in Python?

glglgl
  • 89,107
  • 13
  • 149
  • 217
user1393889
  • 21
  • 1
  • 1
  • 1
    in your example is `file01.out` same than `output_res.txt` ? – Seki May 14 '12 at 14:01
  • 4
    There are plenty of good examples in the [documentation of the `subprocess` module](http://docs.python.org/library/subprocess.html). – Ferdinand Beyer May 14 '12 at 14:03
  • 1
    yes, and a quick search gives a solution for the first part ; http://stackoverflow.com/questions/89228/how-to-call-external-command-in-python – Seki May 14 '12 at 14:05

2 Answers2

1

Have a look at envoy, a sane wrapper around subprocess:

import envoy
r = envoy.run("C:\Program Files\Ansys Inc\v121\ANSYS\bin\intel\ansys121.exe -p AA_T_A -b -i afshin.txt -o file01.out")
mod_1 = open("output_res.txt").read()
print mod_1
Manuel Ebert
  • 8,429
  • 4
  • 40
  • 61
1

I have been use the following lines.

import os;
os.system("\"C:\\Apl\\ANSYS Inc\\v130\\ansys\\bin\\winx64\\ansys130.exe\" -b -j jobname -i InputFile.inp -o jobname.out");