Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Open /dev/pts/x or HANDLE read/write interactive?

Reply
Thread Tools

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

 
 
Alexander Newald
Guest
Posts: n/a
 
      01-15-2004
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


 
Reply With Quote
 
 
 
 
Lukas Mai
Guest
Posts: n/a
 
      01-15-2004
Alexander Newald <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Alexander Newald
Guest
Posts: n/a
 
      01-15-2004
"Lukas Mai" <(E-Mail Removed)> schrieb im Newsbeitrag
news:bu6bho$vml9$(E-Mail Removed)-muenchen.de...
> Alexander Newald <(E-Mail Removed)> 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


 
Reply With Quote
 
Lukas Mai
Guest
Posts: n/a
 
      01-15-2004
Alexander Newald <(E-Mail Removed)> wrote:
> "Lukas Mai" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:bu6bho$vml9$(E-Mail Removed)-muenchen.de...
>> Alexander Newald <(E-Mail Removed)> 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
 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      01-15-2004
"Alexander Newald" <(E-Mail Removed)> 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\\
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      01-15-2004
Brian McCauley <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
Package to handle table text render (handle space or tab betweenthe columns) ? =?ISO-8859-1?Q?KLEIN_St=E9phane?= Python 3 10-06-2006 08:46 AM
Possible to handle web requests without an ASPX page? i.e. have DLL handle request. jdlwright@shaw.ca ASP .Net 2 05-31-2005 05:42 PM
how to handle command line output(not terminal handle) Leon Python 2 11-04-2004 05:16 AM
File Handle Reading Blues: Rereading a File Handle for Input Dietrich Perl 1 07-22-2004 10:02 AM



Advertisments