简体   繁体   English

Python调用可执行程序

[英]Python calling an executable program

I need to call an executable program with Python, let's say: 我需要用Python调用一个可执行程序,让我们说:

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. 我需要使用此可执行应用程序运行txt文件( afshin.txt ),然后获取输出文件,这也是一个txt文件。 In MATLAB for example it would be: 以MATLAB为例,它将是:

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? 你能帮我用Python做吗?

Have a look at envoy , a sane wrapper around subprocess: 看看enuoy ,一个围绕子进程的理智包装器:

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

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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM