Bash Script Which Executes A Python Script Which Prompts User
I have a python script which sometimes prompts the user for input in the form of raw_input('please provide foo'). I have a bash script which among other things executes that python
Solution 1:
It is hard to distinguish between the prompt string and the script output, so need to use a different file to write your prompt from Python. An example with tty is below, but you can also use stderr for prompts:
bash script:
m=$(python d.py)
echo"OUTPUT $m"
python script:
import os
tty=os.open("/dev/tty", os.O_RDWR)
os.write(tty, "Enter> ");
s=raw_input("")
print s
the same bash script should also work with stderr prompts:
python script:
import sys
sys.stderr.write("Enter> ");
s=raw_input("")
print s
Post a Comment for "Bash Script Which Executes A Python Script Which Prompts User"