Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for input in Bash script calling Ruby gets

Tags:

bash

ruby

heroku

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)
like image 289
Yuri Gadow Avatar asked Nov 05 '22 17:11

Yuri Gadow


1 Answers

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; )
like image 91
tommy Avatar answered Nov 10 '22 14:11

tommy