Mail Archives: cygwin/2002/03/14/14:35:16
Brian DOT Kelly AT empireblue DOT com wrote:
> First I'd like to say THANKS!!!!
Brian, you're most welcome.
> Recently, the IO:Pty module was successfully ported to
> work with cygwin-perl. Now it is truly possible to use your
> fhopen method (per Lincoln Stein's chapter on your Telnet
> module) to do Expect-like control of interactive programs using
> your Telnet module on MSWin OS's.
I haven't seen Lincoln's book. Is that chapter available online?
> There's just one sligggghhht problem ...........
>
> It seems that on a MSWin OS there is no way to truly escape the infamous
> CR\LF.
>
> In your "print" subroutine, you "attempt" to do this with the following
> line of code:
The TELNET protocol specifies CR LF as an end-of-line. The
Net::Telnet::print() code you mention converts the OS native EOL
to the TELNET EOL.
If you're using Net::Telnet with a pseudo terminal then yes you
do want the EOL to be just CR.
Probably the best way to do this is just:
$telnet->output_record_separator("\r");
Modifying Net::Telnet to convert CR LF to just CR is definitely
not the right way to do this.
Here's some code that changes a password on SunOS 5.8. Give it a
try on cygwin.
#!/usr/bin/perl
my $oldpw = "";
my $newpw = "";
use Net::Telnet;
$pwd = new Net::Telnet (Timeout => 2,
Errmode => "return",
Dump_log => "/tmp/dump.log");
## Start passwd program.
&spawn($pwd, "passwd")
or die $pwd->errmsg;
## Send existing passwd.
$pwd->waitfor('/password: ?$/i')
or die "no old password prompt: ", $pwd->lastline;
$pwd->print($oldpw);
## Send new passwd.
$pwd->waitfor('/new password: ?$/i')
or die "bad old password: ", $pwd->lastline;
$pwd->print($newpw);
## Send new passwd verification.
$pwd->waitfor('/new password: ?$/i')
or die "bad new password: ", $pwd->lastline;
$pwd->print($newpw);
## Display success or failure.
$pwd->waitfor('/changed/')
or die "bad new password: ", $pwd->lastline;
print $pwd->lastline;
$pwd->close;
exit;
sub spawn {
my($spawn) = shift @_;
my($pty,
$tty,
$tty_fd);
use IO::Pty ();
use POSIX ();
$pty = new IO::Pty
or die $!;
unless ($pid = fork) { # child process
die "problem spawning program: $!\n" unless defined $pid;
use POSIX ();
POSIX::setsid
or die "setsid failed: $!";
$tty = $pty->slave;
$tty_fd = $tty->fileno;
open STDIN, "<&$tty_fd" or die $!;
open STDOUT, ">&$tty_fd" or die $!;
open STDERR, ">&STDOUT" or die $!;
close $pty;
close $tty;
exec @_ == 1 ? $_[0] : @_
or die "problem executing $_[0]: $!\n";
}
$spawn->fhopen($pty)
or return;
$spawn->telnetmode(0);
$spawn->binmode(1);
$spawn->output_record_separator("\r");
$spawn->cmd_remove_mode(1);
1;
} # end sub spawn
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -