如何在ruby脚本中隐藏来自终端的密码输入 [英] How to hide password input from terminal in ruby script

查看:27
本文介绍了如何在ruby脚本中隐藏来自终端的密码输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ruby​​ 的新手.我需要通过 gets 命令接收密码作为输入.

如何在gets调用期间隐藏在终端中输入的密码

解决方案

来自@eclectic923 答案的最佳方法:

需要'io/console'密码 = STDIN.noecho(&:gets).chomp

对于 1.9.3(及更高版本),这需要您在代码中添加 require 'io/console'.

原答案:

Ruby密码"是另一种选择.>

I am new to ruby. I need to receive password as an input through gets command.

How do I hide the password input typed in the terminal, during gets call

解决方案

Best method from @eclectic923's answer:

require 'io/console'
password = STDIN.noecho(&:gets).chomp

For 1.9.3 (and above), this requires you adding require 'io/console' to your code.

Original Answer:

Ruby "Password" is another alternative.

这篇关于如何在ruby脚本中隐藏来自终端的密码输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆