splatohara has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that sets up a telnet session as an object, where I want to then write to that session,(object) but I can not manage to write to the object ie...the telnet session sets up fine but when I want to write in the username/pswd, the deatils I send are not being received....any ideas... code below thanks splat
#!/usr/bin/perl -w use Expect; my $command = new Expect; #print $command "telnet stiletto23-cssp0\r"; $command = Expect->spawn("telnet stiletto23-cssp0") or die "Couldn't s +tart program: $!\n"; sleep 1; #prevent output from being shown on our STDOUT $command->log_stdout(1); #wait 10 seconds for "username:" to appear unless ($command->expect(10, "username:")) { #print "timed out"; } # send "username" and a carriage return to the program print $command "admin\r"; sleep 1; print $command "netra1\r"; print "now here\n";

Replies are listed 'Best First'.
Re: writing to an object (telnet session) using expect
by BUU (Prior) on Oct 02, 2003 at 17:53 UTC
    Uh, why are you using expect? It explictly says in it's docs to not use it for things that other modules already exist for, in this case Net::Telnet which will create a connection and let you do anything you want with it.
Re: writing to an object (telnet session) using expect
by delirium (Chaplain) on Oct 02, 2003 at 19:23 UTC
    How far does it get? What OS is the server on? ( Is "netra1" the password? Did you want us to know that? )

    If the server is Win32, or, say, a Cisco router, you may be having trouble with Telnet options inserting a character in the username as a funky side-effect of session negotiation. If you connected manually, you'd see the character, backspace it, and logon fine.

    But no matter what is causing the problem, as BUU said, you're better off going with the right module: Net::Telnet