问题描述:

I'm having trouble in getting Python AVL.

I need to run a two commands in sequence and get the string of the entire result for further processing:

  1. wine /Applications/avl.exe ~/documents/aerodynamics_project/input_cases/somefile.avl

    This brings up the command prompt of the problem.

  2. OPER to run the case

Ideally, I'd then like to pipe the entire output to a string. I cannot figure out how to do this. Current code:

p = subprocess.Popen("wine /Applications/avl.exe ~/documents/aerodynamics_project/input_cases/1_0.2_-0.26.avl", shell = True)

time.sleep(3)

text = p.communicate("OPER")

print(text)

It runs the first command (showing the results in the terminal) and then does not do anything. Replacing communicate with call just returns AttributeError: 'Popen' object has no attribute 'call', so it clearly runs that far.

网友答案:

Can you try passing as explicit param? And also, use stdin as PIPE

p = subprocess.Popen("wine /Applications/avl.exe ~/documents/aerodynamics_project/input_cases/1_0.2_-0.26.avl", shell = True, stdin=subprocess.PIPE).stdin
time.sleep(3)
text = p.communicate(input="OPER")[0]
print(text.decode())
相关阅读:
Top