问题描述
我在 Windows 机器上运行 Ruby 和 MySQL.
I am running Ruby and MySQL on a Windows box.
我有一些 Ruby 代码需要连接到 MySQL 数据库并执行选择.要连接到数据库,我需要提供密码等.
I have some Ruby code that needs to connect to a MySQL database a perform a select. To connect to the database I need to provide the password among other things.
Ruby 代码可以显示要求输入密码的提示,用户输入密码并按 Enter 键.我需要的是输入的密码显示为一行星号.
The Ruby code can display a prompt requesting the password, the user types in the password and hits the Enter key. What I need is for the password, as it is typed, to be displayed as a line of asterisks.
如何让 Ruby 将键入的密码显示为dos 框"中的一行星号?
How can I get Ruby to display the typed password as a line of asterisks in the 'dos box'?
推荐答案
为了回答我自己的问题,并为了其他想知道的人的利益,有一个名为 HighLine 你需要的.
To answer my own question, and for the benefit of anyone else who would like to know, there is a Ruby gem called HighLine that you need.
require 'rubygems'
require 'highline/import'
def get_password(prompt="Enter Password")
ask(prompt) {|q| q.echo = false}
end
thePassword = get_password()
这篇关于如何从 Ruby 的命令行读取密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!