0

My perl script needs to ask the user for a password to download some files:

print "Your password please: \n";
ReadMode('noecho');
$password = ReadLine(0);
$password =~ s/\n//;
ReadMode(0);

system("wget --user=user --password=\"$password\" http://some.server/data.xml");
do_something();

If I call the script with $> ./script.pl everything works fine. But if I want to pipe the output to a file with $> ./script.pl > text.txt, the password question is piped to the file, too, and the ReadLine does not work any longer.

What is the right way to do this?

d135-1r43
  • 2,485
  • 1
  • 25
  • 33

2 Answers2

3

Print the prompt to STDERR:

print STDERR "Your password please: ";
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
0

The security gain from reading the password directly off the keyboard is nullified by shelling out to wget, in whose environment the password is plainly visible for every user on the system. If security does not matter, you can rewrite your program to take command-line parameters for the user/password.

Community
  • 1
  • 1
daxim
  • 39,270
  • 4
  • 65
  • 132