【发布时间】:2015-09-09 13:29:06
【问题描述】:
我正在为 Xfoil 编写一个包装器,我的第一个命令集是:
commands=[]
commands.append('plop\n')
commands.append('g,f\n')
commands.append('\n')
commands.append('load '+ afile+'\n')
commands.append('\n')
#commands.append('ppar\n');
#commands.append('n %g\n',n);
commands.append('\n')
commands.append('\n')
commands.append('oper\n')
commands.append('iter '+ str(iter) + '\n')
commands.append('visc {0:f}\n'.format(Re))
commands.append('m {0:f}\n'.format(M))
我正在与 xfoil 进行如下交互:
xfoil_path=os.getcwd()+'/xfoil.exe'
Xfoil = Popen(xfoil_path, shell=True, stdin=PIPE, stdout=None, stderr=None, creationflags=0)
for i in commands:
print '\nExecuting:', i
#stdin.write returns None if write is blocked and that seems to be the case here
Xfoil.stdin.write(i)
Xfoil.wait()
#print Xfoil.stdin.write(i)
但是,Xfoil.stdin.write 被阻止与程序交互 - xfoil.exe - 因为 Xfoil.stdin.write(i) 返回 None。
这发生在第一个命令之后,即 plop
我该如何解决这个问题?
【问题讨论】:
-
写完first
command项后,您正在等待程序结束。你确定那不是问题的根源吗? BTWshell=True在这里是不必要的。路径应与os.path.join()结合使用。commands与所有这些append()调用的构建看起来很奇怪。为什么不只创建一个包含这些内容的列表,而不是创建一个空列表并执行所有这些append()s。i对于不是整数的东西来说是个坏名字,尤其是作为循环变量。