![]() |
Open /dev/pts/x or HANDLE read/write interactive?
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 |
Re: Open /dev/pts/x or HANDLE read/write interactive?
Alexander Newald <alexander@newald.de> 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 |
Re: Open /dev/pts/x or HANDLE read/write interactive?
"Lukas Mai" <lmai@mytum.de> schrieb im Newsbeitrag
news:bu6bho$vml9$1@sunsystem5.informatik.tu-muenchen.de... > Alexander Newald <alexander@newald.de> 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 |
Re: Open /dev/pts/x or HANDLE read/write interactive?
Alexander Newald <alexander@newald.de> wrote:
> "Lukas Mai" <lmai@mytum.de> schrieb im Newsbeitrag > news:bu6bho$vml9$1@sunsystem5.informatik.tu-muenchen.de... >> Alexander Newald <alexander@newald.de> 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 |
Re: Open /dev/pts/x or HANDLE read/write interactive?
"Alexander Newald" <alexander@newald.de> 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\\ |
Re: Open /dev/pts/x or HANDLE read/write interactive?
Brian McCauley <nobull@mail.com> 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 tadmc@augustmail.com Perl programming Fort Worth, Texas |
| All times are GMT. The time now is 08:22 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.