By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,933 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,933 IT Pros & Developers. It's quick & easy.

READMODE or READKEY from a file

P: 2
I have a simple perl script as follow:

Expand|Select|Wrap|Line Numbers
  1.   use Term::ReadKey;
  2.  
  3.   print "Enter name: ";
  4.   ReadMode 2; #Turn off keyboard echo
  5.   $name = <>;
  6.   ReadMode 0;
  7.   print "$name \n";
Instead of read the input from keyboard, I would like to get from a file(a file that.only have one line). I did run the following command in Shell:
1) perl test.pl < input.txt
2) cat input.txt | perl test.pl

Both returned the following error:
Expand|Select|Wrap|Line Numbers
  1. GetConsoleMode failed, LastError=|6| at i:/site/lib/Term/ReadKey.pm line 265.
Since the readmode get the input from stdin, and I did pipe the file into stdin, why error out? Anything i did wrong?Any work around?Pls advice.

Thanks
Nov 19 '08 #1
Share this Question
Share on Google+
2 Replies


P: 13
Try removing the redirective "<" when calling the command.

Expand|Select|Wrap|Line Numbers
  1. perl test.pl input.txt
Nov 19 '08 #2

P: 2
Try removing the redirective "<" when calling the command.

Expand|Select|Wrap|Line Numbers
  1. perl test.pl input.txt
It's working. Thanks.
Nov 20 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.