1

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
  • Which Perl distribution are you using on Windows? Is is ActivePerl or Strawberry Perl? Commented Mar 10, 2013 at 7:16
  • 1
    "without CPAN packages?" ... Short answer, no. Commented Mar 10, 2013 at 12:46

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.