Python用输入运行.exe

时间:2016-09-09 14:34:01

标签: python subprocess

我想使用脚本来调用可执行程序并在exe程序(DOS窗口)中输入一些指令来运行这个exe程序(不需要输出)

例如,如果我直接运行该程序,我将双击它并键入如下:

load XXX.txt
oper
quit

这是我的代码,fwiw我对子进程没有深刻的理解。

import subprocess
import os
os.chdir('D:/Design/avl3.35/Avl/Runs')
Process=subprocess.Popen(['avl.exe'], stdin=subprocess.PIPE)
Process.communicate(b'load allegro.avl\n')

当我运行此代码时,我得到以下内容:

 ===================================================
  Athena Vortex Lattice  Program      Version  3.35
  Copyright (C) 2002   Mark Drela, Harold Youngren

  This software comes with ABSOLUTELY NO WARRANTY,
    subject to the GNU General Public License.

  Caveat computor
 ===================================================

 ==========================================================
   Quit    Exit program

  .OPER    Compute operating-point run cases
  .MODE    Eigenvalue analysis of run cases
  .TIME    Time-domain calculations

   LOAD f  Read configuration input file
   MASS f  Read mass distribution file
   CASE f  Read run case file

   CINI    Clear and initialize run cases
   MSET i  Apply mass file data to stored run case(s)

  .PLOP    Plotting options
   NAME s  Specify new configuration name

 AVL   c>  
 Reading file: allegro.avl  ...

 Configuration: Allegro-lite 2M                                             

   Building surface: WING                                    
     Reading airfoil from file: ag35.dat
     Reading airfoil from file: ag36.dat
     Reading airfoil from file: ag37.dat
     Reading airfoil from file: ag38.dat

在文件的第145行../src/userio.f(unit = 5,file ='stdin')#!!!!这里错误!!

Fortran运行时错误:文件结束#!!!!错误在这里!!

   Building duplicate image-surface: WING (YDUP)                             

   Building surface: Horizontal tail                         

   Building duplicate image-surface: Horizontal tail (YDUP)                  

   Building surface: Vertical tail                           

 Mach =    0.0000  (default)
 Nbody =   0      Nsurf =   5      Nstrp =  64      Nvor  = 410

 Initializing run cases...

我不知道这有什么问题,我也不知道为什么错误提示会显示在代码中。搜索后我发现communicate方法是等待进程完成并返回所有输出,虽然我不需要输出,但我仍然不知道该怎么做。

你能解释一下这里发生了什么,我怎么能完成我想做的事情?

0 个答案:

没有答案