Search code examples
pythonstdinpopen

stdin.write() being blocked from interacting with foil.exe


I'm writing a wrapper for Xfoil and my first command set of commands are:

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

I'm interacting with xfoil as below:

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)

However, Xfoil.stdin.write is being blocked form interacting with the program -- xfoil.exe -- as Xfoil.stdin.write(i) returns a None.

This happens immediately after the first command i.e. plop

How do I resolve this?


Solution

  • Solution is to add Xfoil.stdin.close(); Closing the buffer allows the program to proceed.

    Xfoil = Popen(xfoil_path, shell=True, stdin=PIPE, stdout=None, stderr=None, creationflags=0)
    for i in commands:
        Xfoil.stdin.write(i)
    
    Xfoil.stdin.close()
    Xfoil.wait()
    

    Seeking help understand why Xfoil.stdin.close() needs to be added. How does closing the buffer allow xfoil.exe to proceed?