I have a question regarding subprocess.Popen .I'm calling a shell script and provide fewinputs. After few inputs ,I want user running the python script to input.
Is it possible to transfer control from Popen process to command line.
I've added sample scripts
sample.sh
echo "hi"
read input_var
echo "hello" $input_var
read input_var1
echo "Whats up" $input_var1
read input_var2
echo "Tell something else" $input_var2
test.py
import os
from subprocess import Popen, PIPE
p=Popen([path to sample.sh],stdin=PIPE)
#sample.sh prints asks for input
p.stdin.write("a\n")
#Prompts for input
p.stdin.write("nothing much\n")
#After the above statement ,User should be able to prompt input
#Is it possible to transfer control from Popen to command line
Output of the program python test.py
hi
hello a
Whats up b
Tell something else
Please suggest if any alternate methods available to solve this
p=Popen([path to sample.sh],stdin=PIPE)was given. And later I triedp=Popen(["./sample.sh"],stdin=PIPE).I didn't see any error messages.I pass first two variables from python to shell script and expect third one to be entered from user.However code doesn't ask for third variable .I'm not able to attach screenshot. I'm running this program from putty ssh session. - Abhishek Lsample.shgiven without proper path.I used to getNameErrorerror.I have corrected the question.After correctingtest.pyit or after running it inside actual directory within quotes./sample.sh,I'm facing above problem.Please guide if anyone has faced this issue earlier. - Abhishek L