You can use the subprocessmethod Popen.communicate:
import subprocess
def create_grid(*commands):
process = subprocess.Popen(
['grid.exe'],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
process.communicate('\n'.join(commands) + '\n')
if __name__ == '__main__':
create_grid('grid.grd', 'yes', 'not really')
The “communication” method essentially goes through the input, as if you were entering it. Be sure to end each line of input with a newline.
, grid.exe , create_grid, :
def create_grid(*commands):
process = subprocess.Popen(
['grid.exe'],
stdin=subprocess.PIPE)
process.communicate('\n'.join(commands) + '\n')
: , , .