I've a Bash script using some Heroku client commands, e.g., heroku create. Those commands are written in Ruby and include calls to IO::gets to gather the user's name and password. But, if they are called from within a Bash script, it seems to advance to the last gets. For example, in the case where the Heroku client is going to ask for email and password, the first is skipped and the user can only enter their password:
Enter your Heroku credentials.
Email: Password: _
Is there a way to fix or jury-rig the Bash script to prevent this from happening (it does not happen when the exact same command is run by hand from the command line.) Or something that must be changed in the Ruby?
[UPDATE - Solution]
I wasn't able to solve the problem above, but @geekosaur's answer to another question put me on the right track to making the terminal "available" to the Ruby script running inside the Bash. I changed all:
curl -s http://example.com/bash.sh | bash
and
bash < <(curl -s http://example.com/bash.sh)
to be
bash <(curl -s http://example.com/bash.sh)
Try to reopen stdin
on the controlling terminal device /dev/tty
.
exec 0</dev/tty # Bash
$stdin.reopen(File.open("/dev/tty", "r")) # Ruby
# Bash examples
: | ( read var; echo $var; )
: | ( read var </dev/tty; echo $var; )
: | ( exec 0</dev/tty; read var; echo $var; )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With