等待调用 Ruby gets 的 Bash 脚本中的输入
我有一个使用一些 Heroku 客户端命令的 Bash 脚本,例如,heroku create。这些命令是用 Ruby 编写的,包含调用 到 IO::gets 收集用户名和密码。但是,如果从 Bash 脚本内调用它们,则似乎会前进到最后一次获取。例如,在 Heroku 客户端要求提供电子邮件和密码的情况下,第一个被跳过,用户只能输入密码:
Enter your Heroku credentials.
Email: Password: _
有没有办法修复或临时操纵 Bash 脚本以防止这种情况发生(当从命令行手动运行完全相同的命令时,不会发生这种情况。)或者必须在 Ruby 中更改某些内容?
[更新 - 解决方案]
我无法解决上述问题,但是@geekosaur 对另一个问题的回答 让我走上了正确的道路,让终端对 Bash 中运行的 Ruby 脚本“可用”。我改变了一切:
curl -s http://example.com/bash.sh | bash
并且
bash < <(curl -s http://example.com/bash.sh)
成为
bash <(curl -s http://example.com/bash.sh)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在控制终端设备
/dev/tty
上重新打开stdin
。Try to reopen
stdin
on the controlling terminal device/dev/tty
.