For example, the shell script takes an integer at a prompt and returns it.
Enter an integer:
--> 3
3
I'm using subprocess.check_call(["./myScript"])
to run the shell script. How can I automate sending the "3"
in as in the example above? So far all my searching has only recovered how to run a script with command line arguments, not this kind of manual input.
You probably want to use the
subprocess.Popen.communicate()
function. The docs are quite expressive.As the earlier answer explained
subprocess.Popen
can be used to create process that can be interacted withcommunicate
.communicate
takes string as a parameter that will be passed to the created process and returns tuple(stdout, stderr)
. Below is a short example of two Python scripts communicating with it:Child
Parent
Output