tags:

views:

97

answers:

2

I'm using the OS.System command to call a python script.

example:

OS.System("call jython script.py")

In the script I'm calling, the following command is present:

x = raw_input("Waiting for input")

If I run script.py from the command line I can input data no problem, if I run it via the automated approach I get an EOFError. I've read in the past that this happens because the system expects a computer to be running it and therefore could never receive input data in this way.

So the question is how can I get python to wait for user input while being run in an automated way?

A: 

Your question is a bit unclear. What is the process calling your Python script and how is it being run? If the parent process has no standard input, the child won't have it either.

Marius Gedminas
+2  A: 

The problem is the way you run your child script. Since you use os.system() the script's input channel is closed immediately and the raw_input() prompt hits an EOF (end of file). And even if that didn't happen, you wouldn't have a way to actually send some input text to the child as I assume you'd want given that you are using raw_input().

You should use the subprocess module instead.

import subprocess
from subprocess import PIPE

p = subprocess.Popen(["jython", "script.py"], stdin=PIPE, stdout=PIPE)
print p.communicate("My input")
Alexander Ljungberg