Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: Jay Rogers To: Brian DOT Kelly AT empireblue DOT com CC: cygwin AT cygwin DOT com, gbarr AT pobox DOT co, nik AT tiuk DOT ti DOT com, RGiersig AT cpan DOT org, perl5-porters AT perl DOT org, lstein AT cshl DOT org, reedfish AT ix DOT netcom DOT com, codyvero AT pilot DOT msu DOT edu In-reply-to: <85256B6D.0002FA1F.00@wt1hub01.empirehealthcare.com> (Brian DOT Kelly AT empireblue DOT com) Subject: Re: Net::Telnet needs line of code added for fhopen to work with cygwin-perl and IO::Pty module in MSWin References: <85256B6D DOT 0002FA1F DOT 00 AT wt1hub01 DOT empirehealthcare DOT com> Reply-to: Jay Rogers Message-Id: Date: Thu, 14 Mar 2002 14:27:10 -0500 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/