title: Using Python to run executable and fill in user input
body: <p>I'm trying to use Python to automate a process that involves calling a Fortran executable and submitting some user inputs.  I've spent a few hours reading through similar questions and trying different things, but haven't had any luck.  Here is a minimal example to show what I tried last</p>
  
  <pre><code>#!/usr/bin/python
  
  import subprocess
  
  # Calling executable 
  ps = subprocess.Popen('fortranExecutable',shell=True,stdin=subprocess.PIPE)
  ps.communicate('argument 1')
  ps.communicate('argument 2')
  </code></pre>
  
  <p>However, when I try to run this, I get the following error:</p>
  
  <pre><code>  File "gridGen.py", line 216, in &lt;module&gt;
      ps.communicate(outputName)
    File "/opt/apps/python/epd/7.2.2/lib/python2.7/subprocess.py", line 737, in communicate
      self.stdin.write(input)
  ValueError: I/O operation on closed file
  </code></pre>
  
  <p>Any suggestions or pointers are greatly appreciated.</p>
  
  <p>EDIT:</p>
  
  <p>When I call the Fortran executable, it asks for user input as follows:</p>
  
  <pre><code>fortranExecutable
  Enter name of input file: 'this is where I want to put argument 1'
  Enter name of output file: 'this is where I want to put argument 2'
  </code></pre>
  
  <p>Somehow, I need to run the executable, wait until it asks for user input and then supply that input.</p>