Read password using Perl on Windows without using CPAN packages

吃可爱长大的小学妹 提交于 2019-12-11 10:27:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!