pexpect PopenSpawn没有运行命令并且什么也不输出

时间:2019-02-20 00:40:09

标签: python subprocess popen pexpect

我正在尝试使用pexpect.popen_spawn.PopenSpawn运行.exe文件。但是该功能一直运行到超时。即使在那之后,它也不接受输入,什么也不输出。

这是代码和输出

代码:

from pexpect import EOF, TIMEOUT
from pexpect.popen_spawn import PopenSpawn

child = PopenSpawn("xfoil.exe")
child.logfile = open("child.log", "wb")

def cmdin(expect, cmd, timelimit):
    outputs = [expect, TIMEOUT, EOF]
    result = child.expect(outputs, timeout=timelimit) 
    child.sendline(cmd)
    print(f"expect inputted: {expect}\n" + 
          f"expect outputted is: {outputs[result]}\n" + 
          f"sendline: {cmd}\n" + 
          f"stdout: {child.before.decode()}\n")

timelimit = 10
cmdin(b"\s*XFOIL\s*c>\s*", "naca0012", timelimit)

输出为

expect inputted: b'\\s*XFOIL\\s*c>\\s*'
expect outputted is: <class 'pexpect.exceptions.TIMEOUT'>
sendline: naca0012
stdout: 

预期输出为

 expect inputted: b'\\s*XFOIL\\s*c>\\s*'
 expect outputted is: b'\\s*XFOIL\\s*c>\\s*'
 sendline: naca0012
 stdout:      XFOIL   c>  naca0012
 Max thickness =     0.120035  at x =   0.300
 Max camber    =     0.000000  at x =   0.013

 Buffer airfoil set using 331 points

 Blunt trailing edge.  Gap =  0.00252

 Paneling parameters used...
   Number of panel nodes       160
   Panel bunching parameter    1.000
   TE/LE panel density ratio   0.150
   Refined-area/LE panel density ratio    0.200
   Top    side refined area x/c limits  1.000 1.000
   Bottom side refined area x/c limits  1.000 1.000

谁能告诉我如何解决此问题。

非常感谢。

0 个答案:

没有答案