5

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)
Community
  • 1
  • 1
Yuri Gadow
  • 1,814
  • 2
  • 16
  • 26

1 Answers1

2

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; )
tommy
  • 36
  • 1
  • "reopen"? Can you explain what this means, or why it needs to be done? Thanks – noli Jul 27 '11 at 11:47
  • I expect this would work, since the problem is the lack of a terminal/stdin to read from. But, since this solution would require changing the Ruby to attempt to grab stdin somehow (perhaps not even possible if there's *no* terminal) it wouldn't be very flexible. Instead I addressed the root cause, which was not having a terminal--see my update to the Q. – Yuri Gadow Jul 27 '11 at 17:41