问题
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.
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.
Is there a way to read a password in Perl without using the terminal or ReadKey/Readline?
回答1:
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);
This solution requires the installation of Term::ReadKey, and it works it Windows also.
回答2:
Instructions on installing CPAN modules with ActivePerl may be found here:
How to install CPAN modules into ActivePerl
Instructions on installing CPAN modules with Strawberry Perl may be found here:
Strawberry Perl CPAN instructions
来源:https://stackoverflow.com/questions/15319768/read-password-using-perl-on-windows-without-using-cpan-packages