2

I am building an interactive installer using a nifty command line:

curl -L http://install.example.com | bash

The bash script then rapidly delegates to a python script:

# file: install.sh
[...]
echo "-=- Welcome -=-"
[...]
/usr/bin/env python3 deploy_p3k.py

And the python script itself prompts the user for input:

# file: deploy_py3k.py
[...]
input('====> Confirm or enter installation directory [/srv/vhosts/project]: ')
[...]
input('====> Confirm installation [y/n]: ')
[...]

PROBLEM: Because the python script is ran from a bash script itself being piped from curl, when the prompt comes up, it is automatically "skipped" and everything ends like so:

$ curl -L http://install.example.com | bash
-=- Welcome ! -=-
We have detected you have python3 installed.
====> Confirm or enter installation directory [/srv/vhosts/project]: ====> Confirm installation [y/n]: Installation aborted.

As you can see, the script doesn't wait for user input, because of the pipe which ties the input to the curl output. Thus, we have the following problem:

curl [STDOUT]=>[STDIN] BASH (which executes python script)
= the [STDIN] of the python script is the [STDOUT] of curl (which contains at a EOF) !

How can I keep this very useful and short command line (curl -L http://install.example.com | bash) and still be able to prompt the user for input ? I should somehow detach the stdin of python from curl but I didn't find how to do it.

Thanks very much for your help !

Things I have also tried:

  • Starting the python script in a subshell: $(/usr/bin/env python3 deploy.py)

1 Answer 1

2

You can always redirect standard input from the controlling tty, assuming there is one:

/usr/bin/env python3 deploy_p3k.py < /dev/tty

or

/usr/bin/env python3 deploy_p3k.py <&1
Sign up to request clarification or add additional context in comments.

4 Comments

Why are you redirecting the STDERR to STDOUT (with 2>&1) ?
For completeness' sake. I couldn't tell from your description whether they had been redirected and/or whether they were required by the python script. In any event, the key to your specific question is < /dev/tty
Yes, the < /dev/tty was enough. Thank you very much !
FWIW, an alternative solution is /usr/bin/env python3 deploy_p3k.py <&1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.