Find the answer to your Linux question:
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 ...
  1. #1
    Just 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:
    Code:
    print "Please enter a number: ";
    my $number = <STDIN>;
    How do I read input from console?
    Code:
    open (CONSOLE, "> /dev/ttyS0");
    print CONSOLE "Please enter a number: ";
    #read input from console here???

  2. #2
    Linux Newbie danielsmw's Avatar
    Join Date
    Nov 2006
    Location
    Clemson, SC / Charleston, SC
    Posts
    110
    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:
    Code:
    open(CONSOLE_IN, "< /dev/ttyS0");
    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.

    Basically, if you ran your script like this:
    Code:
    user@host $ perl myscript.pl < fileorfilehandle
    Then STDIN would read from the input file. For any case where that's left off; that's to say, you just have
    Code:
    user@host $ perl myscript.pl
    Then reading from keyboard input on the current console is the default for STDIN.

    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

  3. #3
    Linux Newbie
    Join Date
    Jul 2008
    Location
    Anaheim, CA
    Posts
    114
    i think he means the console's output after he enters a code.

  4. #4
    Just 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

  5. #5
    Just 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...