Results 1 to 5 of 5
How do I read input from console (/dev/ttyS0)? Normally, perl script read from standard input:
Code:
print "Please enter a number: ";
my $number = <STDIN>;
How do I read ...
- 10-14-2008 #1Just Joined!
- Join Date
- Sep 2008
- Location
- Tacoma, Washington
- Posts
- 8
Read input from console
How do I read input from console (/dev/ttyS0)? Normally, perl script read from standard input:
How do I read input from console?Code:print "Please enter a number: "; my $number = <STDIN>;
Code:open (CONSOLE, "> /dev/ttyS0"); print CONSOLE "Please enter a number: "; #read input from console here???
- 10-14-2008 #2
Well, firstly, I can't imagine why STDIN wouldn't automatically take input from the console. By default, STDIN takes keyboard input.
If you wanted to, you could open a file handle:
But to be totally honest, I'm not sure that that would actually work as intended. I think all you're really looking for is what you had.Code:open(CONSOLE_IN, "< /dev/ttyS0");
Basically, if you ran your script like this:
Then STDIN would read from the input file. For any case where that's left off; that's to say, you just haveCode:user@host $ perl myscript.pl < fileorfilehandle
Then reading from keyboard input on the current console is the default for STDIN.Code:user@host $ perl myscript.pl
Does that answer your question, or is there a deeper problem that I just didn't understand from your post?Registered Linux User: #479567
Asking a question? Read this page first.
Now... sudo make me a sandwich.
ratiocinativeroot.blogspot.com
- 10-14-2008 #3Linux Newbie
- Join Date
- Jul 2008
- Location
- Anaheim, CA
- Posts
- 114
i think he means the console's output after he enters a code.
- 10-14-2008 #4Just Joined!
- Join Date
- Sep 2008
- Location
- Tacoma, Washington
- Posts
- 8
Let say I have a linux box without pci graphic card and using console for display. At start up, it automatically run my perl script. However, I need the user to enter the option input. I use putty or hyperterminal for console. I cannot use keyboard to enter in putty or hyperterminal window? I try to type something in putty window but it seems like I cannot. Is there a way I can config this and how to read the input from my script?
Thanks,
nodopro
- 10-14-2008 #5Just Joined!
- Join Date
- Sep 2008
- Location
- Tacoma, Washington
- Posts
- 8
I got it. Here is what I did.
open (OUTCONSOLE, "> /dev/ttyS0");
print OUTCONSOLE "Please enter a number: ";
open (INCONSOLE, "< /dev/ttyS0");
my $number = <INCONSOLE>;
close OUTCONSOLE;
close INCONSOLE;
Thanks Daniel for your suggestion, open filehandle to read.
-nodopro


Reply With Quote