Open /dev/pts/x or HANDLE read/write interactive?

Discussion in 'Perl Misc' started by Alexander Newald, Jan 15, 2004.

  1. Hello,

    I have a setup (linux) where a program (uml) uses /dev/pts/x as a virtual
    console with a login prompt. I now like to use a perl script to interactiv
    use this virtual console.

    I tried:

    #!/usr/bin/perl
    open(HANDLE,"/dev/pts/x");
    while(<HANDLE>) { print $_; }
    close(HANDLE);
    print "Read ok\n";

    But I noticed that I never will reach the last line "Read ok" because my
    script doesn't recognize the end of the /dev/pts/x that sure is right
    because it has no real end of file.

    After some google work I found IO::Select and ->can_read / ->can_write

    #!/usr/bin/perl
    use IO::Select
    $sel = IO::Select->new();
    open(HANDLE,"/dev/pts/x");
    $sel->add(\*HANDLE);
    while (true) {
    while(@ready = $sel->can_read) {
    #
    # I thought about something like
    #
    print ">";chomp($tmp = <STDIN>);
    print HANDLE "$tmp\n";
    #
    # But it isn't working
    #
    }
    while(@ready = $sel->can_write) {
    #
    # What to do here to get the "output" of /dev/pts/x ?
    #
    }
    }

    I can see that /dev/pts/x contains some data:

    -- snip --
    bash> cat /dev/pts/x

    Debian GNU/Linux 3.0 vserver tty1

    vserver login:
    -- snip --

    Here is what I want to get: A webpage that will print the output of
    /dev/pts/x on a webpage and return the user input to /dev/pts/x to access
    the virtual console (/dev/pts/x) from a webpage.

    Thanks,

    Alexander Newald
     
    Alexander Newald, Jan 15, 2004
    #1
    1. Advertising

  2. Alexander Newald

    Lukas Mai Guest

    Alexander Newald <> wrote:
    > Hello,


    > I have a setup (linux) where a program (uml) uses /dev/pts/x as a virtual
    > console with a login prompt. I now like to use a perl script to interactiv
    > use this virtual console.


    [...]

    > #!/usr/bin/perl

    use warnings;
    use strict;

    > use IO::Select
    > $sel = IO::Select->new();
    > open(HANDLE,"/dev/pts/x");

    open(HANDLE, '<', '/dev/pts/x') or die "/dev/pts/x: $!";

    > $sel->add(\*HANDLE);
    > while (true) {

    ^^^^
    Do you know what "true" is? (Hint: It's not a perl builtin.)

    [rest of code snipped]

    HTH, Lukas
     
    Lukas Mai, Jan 15, 2004
    #2
    1. Advertising

  3. "Lukas Mai" <> schrieb im Newsbeitrag
    news:bu6bho$vml9$-muenchen.de...
    > Alexander Newald <> wrote:
    > > Hello,

    >
    > > I have a setup (linux) where a program (uml) uses /dev/pts/x as a

    virtual
    > > console with a login prompt. I now like to use a perl script to

    interactiv
    > > use this virtual console.

    >
    > [...]
    >
    > > #!/usr/bin/perl

    > use warnings;
    > use strict;
    >
    > > use IO::Select
    > > $sel = IO::Select->new();
    > > open(HANDLE,"/dev/pts/x");

    > open(HANDLE, '<', '/dev/pts/x') or die "/dev/pts/x: $!";


    I now get

    "IO::Select=ARRAY(0x812c670)" is not exported by the IO::Select module
    Can't continue after import errors at ./test line 5
    BEGIN failed--compilation aborted at ./test line 5.

    > > $sel->add(\*HANDLE);
    > > while (true) {

    > ^^^^
    > Do you know what "true" is? (Hint: It's not a perl builtin.)


    I didn't know that and will change that in the future.

    > [rest of code snipped]
    >
    > HTH, Lukas


    In general: is this the right way to solve the problem?

    Alexander Newald
     
    Alexander Newald, Jan 15, 2004
    #3
  4. Alexander Newald

    Lukas Mai Guest

    Alexander Newald <> wrote:
    > "Lukas Mai" <> schrieb im Newsbeitrag
    > news:bu6bho$vml9$-muenchen.de...
    >> Alexander Newald <> wrote:
    >>
    >> [...]
    >>
    >> > #!/usr/bin/perl

    >> use warnings;
    >> use strict;
    >>
    >> > use IO::Select

    ^^^ missing ';'

    >> > $sel = IO::Select->new();

    perl sees ``use IO::Select ($sel = IO::Select->new());''

    >> > open(HANDLE,"/dev/pts/x");

    >> open(HANDLE, '<', '/dev/pts/x') or die "/dev/pts/x: $!";


    > I now get


    > "IO::Select=ARRAY(0x812c670)" is not exported by the IO::Select module
    > Can't continue after import errors at ./test line 5
    > BEGIN failed--compilation aborted at ./test line 5.


    Yes, that's because you're trying to export the result of IO::Select->new().

    [...]

    > In general: is this the right way to solve the problem?


    I'm sorry, I can't help you there.

    Lukas
     
    Lukas Mai, Jan 15, 2004
    #4
  5. "Alexander Newald" <> writes:

    > > > use IO::Select
    > > > $sel = IO::Select->new();


    > "IO::Select=ARRAY(0x812c670)" is not exported by the IO::Select module
    > Can't continue after import errors at ./test line 5
    > BEGIN failed--compilation aborted at ./test line 5.


    Yeah, leaving out a semicolon and thus causing Perl to run two
    statements into one can often give some really weird errors. This is
    particularly true when the first is a use().

    --
    \\ ( )
    . _\\__[oo
    .__/ \\ /\@
    . l___\\
    # ll l\\
    ###LL LL\\
     
    Brian McCauley, Jan 15, 2004
    #5
  6. Brian McCauley <> wrote:

    > Yeah, leaving out a semicolon and thus causing Perl to run two
    > statements into one can often give some really weird errors. This is
    > particularly true when the first is a use().



    That has embarrassed me many times. When the trainer can't figure
    out what's wrong with the student's program it doesn't look good.

    It has happened so often, that I added this to the lecture part:

    If you get messages from the Twilight Zone, check to see if
    you've missed a semicolon after your "use strict".



    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 15, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia

    1000 pts datagrid to excel with columns readonly

    Luis Esteban Valencia, Jan 7, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    546
    Raterus
    Jan 7, 2005
  2. =?Utf-8?B?VmlqYXk=?=

    Parser Error Message: Could not load type 'PTS.Global'.

    =?Utf-8?B?VmlqYXk=?=, May 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,468
    Brock Allen
    May 25, 2005
  3. Todd Gardner
    Replies:
    2
    Views:
    117
    Todd Gardner
    Jun 21, 2004
  4. Andreas Persson
    Replies:
    2
    Views:
    322
    Andreas Persson
    Mar 3, 2004
  5. Iulian Ilea
    Replies:
    1
    Views:
    343
    pcx99
    Dec 21, 2006
Loading...

Share This Page