I have a bash script bash.sh
that looks like this:
#!/usr/bin/env bash
/usr/local/sbin/pythonScript.py firstArgument secondArgument
If I call the pythonScript.py from my terminal with the two command line arguments it asks me the question " Do you really want to accept this arguments ? ( yes / no )"
and I have to type yes or no and press enter in the terminal in order to resume the script execution.
Now I want that my bash.sh
script is doing the yes
answer for me but I have no clue how.
I tried something like this in my script bash.sh
#!/usr/bin/env bash
echo "yes\n" | /usr/local/sbin/pythonScript.py firstArgument secondArgument
Can anyone help me how to provide dynamic command line arguments to a python script and also simulate the ENTER key press.
EDIT:
The python script is reading from On Unix, the prompt is written to the file-like object stream. stream defaults to the controlling terminal (/dev/tty)
echo "yes"
(no\n
) will send the stringyes
followed by a newline. This will work unless the Python code is reading directly from the TTY (i.e. not from standard input). Does this not work for you?echo "yes\n"
from Bash will output the literal stringyes\n
(followed by a newline), which may not be what your python program expects.expect
. It's a tool for the cases like yours.echo -e "yes\n"