65
58

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

パスワード等の標準入力を隠す

Posted at

コンソールスクリプトなどで、パスワードを隠しつつ入力させたい時があります。
そんな時、 Ruby 1.9.3 以降であれば、 IO#noecho が使えます。

require 'io/console'

password = STDIN.noecho(&:gets)

Ruby 1.9.3 以前であれば、 highline gem を利用するのが簡単です。

require 'highline/import'

password = ask("Enter password: ") { |q| q.echo = false }
65
58
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
65
58

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?