在Windows上使用Perl读取密码,而不使用CPAN软件包 [英] Read password using Perl on Windows without using CPAN packages
问题描述
我们有一个Perl脚本,该脚本使用终端读取密码.该脚本在Windows上不起作用,因为终端不可用.
We have a Perl script that uses the terminal to read a password. This script does not work on Windows as the terminal is not available.
我们进行了一些研究,发现ReadKey/Readline是替代方法.但是,此软件包不是我们的默认Perl安装的一部分.
We did some research and found that ReadKey/Readline is an alternative for this. However, this package is not part of our default Perl install.
是否可以在不使用终端或ReadKey/Readline的情况下在Perl中读取密码?
Is there a way to read a password in Perl without using the terminal or ReadKey/Readline?
推荐答案
如果您正在寻找一种无需回显终端机即可获取密码的方法,请尝试以下操作:
If you are looking for a way of getting the password without echoing in the terminal, try this:
use Term::ReadKey;
print "Enter password:";
ReadMode('noecho');
my $password = <STDIN>;
chomp($password);
稍后,如果您必须返回到正常的终端输入回波,请编写以下代码:
Later, if you have to back to normal terminal input echo, write this:
ReadMode(0);
此解决方案需要安装 Term :: ReadKey ,并且可以正常工作Windows也是如此.
This solution requires the installation of Term::ReadKey, and it works it Windows also.
这篇关于在Windows上使用Perl读取密码,而不使用CPAN软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!