I am trying to invoke a shell script from python.
This shell script while running expects user inputs based on which it proceeds to perform several actions.
I want to automate the process of sending the user inputs(may be from a file)
I am using the subprocess Popen class to invoke the script and then the Popen.communicate method to pass the user inputs.
The communicate method only passes the first input and the next set of inputs are not passed
Can anyone please guide me further on this
# Shell Script Ex.sh PASS="password" PIN="123" read -s -p "Password: " mypwd echo "" [ "$mypwd" == "$PASS" ] && echo "Password accepted" || echo "Access Denied" read -s -p "PIN: " mypin echo "" [ "$mypin" == "$PIN" ] && echo "PIN accepted" || echo "PIN mismatch"
#python script import os from subprocess import Popen, PIPE proc=Popen('./Ex.sh',stdin=PIPE) proc.communicate('password') proc.communicate('123')