4

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)

4
  • echo "yes" (no \n) will send the string yes 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?
    – Kusalananda
    Commented Dec 11, 2017 at 13:23
  • And echo "yes\n" from Bash will output the literal string yes\n (followed by a newline), which may not be what your python program expects.
    – ilkkachu
    Commented Dec 11, 2017 at 13:34
  • 4
    Maybe it's not exact answer for your question but please take a look at expect. It's a tool for the cases like yours.
    – pawel7318
    Commented Dec 11, 2017 at 14:11
  • 1
    You can also try echo -e "yes\n"
    – pawel7318
    Commented Dec 11, 2017 at 14:20

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.