How can I communicate between two python scripts?
<p>I have a 3d party python script which takes input from the command line.  The relevant code from this script (input.py) looks like the following:</p>

<pre><code>import sys

def chooseinput():
    valid_inputs = ('a', 'b')
    inp = raw_input('Enter choice (%s): ' % "/".join(valid_inputs))
    if inp not in valid_inputs:
        sys.stderr.write("Unsupported input %s\n" % inp)
        return
    print 'You chose ' + '\'' + inp + '\''
    return inp

if __name__ == "__main__":
    chooseinput()
    # do something with the input...
    chooseinput()
    # do something with the input...
</code></pre>

<p>I'm trying to write another python script (harness.py) to generate the inputs for the above script.</p>

<pre><code>import subprocess

def harness():
    p = subprocess.Popen(['python', 'input.py'], stdin=subprocess.PIPE)
    p.stdin.write('a')
    p.stdin.write('b')

if __name__ == '__main__':
    harness()
</code></pre>

<p>From the command line, I run:</p>

<pre><code>$ python harness.py
Enter choice (a/b): Enter choice (a/b): Traceback (most recent call last):
  File "input.py", line 13, in &lt;module&gt;
    chooseinput()
  File "input.py", line 5, in chooseinput
    inp = raw_input('Enter choice (%s): ' % "/".join(valid_inputs))
EOFError: EOF when reading a line
</code></pre>

<p>If I only have one input in the first script, then I can make the second script work by removing the second write call.  If the first script requires more than one input, then I get the above error.</p>
