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

A

Alexander Newald

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
 
L

Lukas Mai

Alexander Newald said:
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
 
A

Alexander Newald

Lukas Mai said:
Alexander Newald said:
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.
^^^^
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
 
L

Lukas Mai

Alexander Newald said:
Lukas Mai said:
[...]
#!/usr/bin/perl
use warnings;
use strict;
use IO::Select
^^^ missing ';'
perl sees ``use IO::Select ($sel = IO::Select->new());''
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
 
B

Brian McCauley

"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\\
 
T

Tad McClellan

Brian McCauley said:
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".
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top