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

Hi Monks, I'm getting the following error from the code that I've posted below. I've included the input below the code. Based upon what the input (dump) shows, I would expect my simple 'ls' command test to be OK. It's not and I'm befuddled. Please suggest what I should try next. Thanks much.

The output/error:
Connecting to baby ... timed-out waiting for command prompt at stopserver.pl line 28
The code:
use Warnings; use Net::Telnet (); use Cwd; $file="inputLog.txt"; $ofile="outputlog.txt"; # build an array of the servers we want to talk to @hosts = ("scary", "baby", "posh"); foreach $host (sort @hosts) { $t = new Net::Telnet (Timeout => 10, Input_log => $file, Output_log => $ofile); print "\nConnecting to $host ...\n"; $t->open("$host"); $t->login(abcde,abc123); my @lines = $t->cmd('ls'); print "$host: Directory Contents:\n"; print "@lines \n"; $t->close; }
The input log:
Welcome to Microsoft Telnet Service login: abcde password: *=============================================================== Welcome to Microsoft Telnet Server. *=============================================================== C:\Documents and Settings\Administrator>

Replies are listed 'Best First'.
Re: Net::Telnet + command prompt
by NetWallah (Canon) on Mar 06, 2008 at 20:19 UTC
    Things to try:

    • Set the Telenet object ($t) prompt to ">", before the cmd method
    • Use "dir" instead of "ls" - M$ likes that better
    • Have you considered using "rcmd" from the Server resource kit (not sure if it is still supported, but this lets you run commands remotely, and get responses at originating machine).
    • Another alternative is psexec

         "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom

Re: Net::Telnet + command prompt
by regexes (Hermit) on Mar 07, 2008 at 10:12 UTC
    Hello,

    To expand on NetWallah's response...

    I find it easier to set my own prompt. That way you always know what's being returned. Look at Net::Telnet --> method: prompt

    Here's an example:
    $host->login( $username, $password ); my $prompt = "_MYPROMPT_"; $host->prompt("/$prompt\$/"); $host->cmd("prompt = $prompt");
    I don't what you're programming/developing but another thing you might want to be aware of is the trickiness of Microsoft's own "telnet server".

    See the Net::Telnet documentation under the heading: Connecting to a Remote MS-Windows Machine

    Hope it helps..

    regexes


    -------------------------
    Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan "press on" has solved and always will solve the problems of the human race.
    -- Calvin Coolidge, 30th President of the USA.
      Solved! The code to do so is the following:

      foreach $host (sort @hosts) { $t = new Net::Telnet (Timeout => 10, Input_log => $file, Prompt => "/\>/"); print "\n\nConnecting to $host ...\n"; $t->open("$host"); $t->login("abc","abc123"); my @lines = $t->cmd('dir'); print "$host: Directory Contents:\n"; print "@lines \n"; $t->close; }
      Thanks to all for your help.
        Hi everyone, I'm trying to connect through telnet to windows ce, but the prompt is "\> " I don't can to send commands because I've this error: pattern match read eof at telnettest.pl line 185"" please someone who can help me!!!