簡體   English   中英

等待調用Ruby gets的Bash腳本中的輸入

[英]Wait for input in Bash script calling Ruby gets

我有一個使用某些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)

嘗試在控制終端設備/dev/tty上重新打開stdin

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; )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM