Read password using Perl on Windows without using

2019-08-08 02:55发布

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?

2条回答
在下西门庆
2楼-- · 2019-08-08 03:26

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.

查看更多
女痞
3楼-- · 2019-08-08 03:35

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

查看更多
登录 后发表回答