achedeuzot
achedeuzot

Reputation: 4404

Python script not waiting for user input when ran from piped bash script

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:

Upvotes: 2

Views: 1232

Answers (1)

Robᵩ
Robᵩ

Reputation: 168866

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

Upvotes: 2

Related Questions