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

Hi,

I am trying to telnet from a WinXP machine to another WINNT Svr and execute a series of Batch files. I am able to login successfully and change directories. However, PERL times out at this place. It doesn't go onto the next line. Here is my code:

#!C:\Perl\bin\perl use warnings; use Net::Telnet; $telnet = new Net::Telnet ( Timeout=>40, Dump_log=>'dump.log', Input_log=>'input.log', Output_log=>'output.log', Errmode=>'die'); $telnet->open('x.x.x.x'); $telnet->waitfor('/login/'); $telnet->print("vtat"); print "Login Entered\n"; $telnet->waitfor('/password:/'); $telnet->print("vtat"); print "Password Entered\n"; $telnet->waitfor('/.*\\n/'); $telnet->cmd("cd c:\\Documents and Settings\\vtat\\SCRIPTS\\SCL"); $telnet->waitfor('/.*\\n/'); print $telnet->cmd("Batchfile1.bat"); $telnet->waitfor('/complete/'); print $telnet->cmd("Batchfile2.bat $telnet->close;

Here is the output from the input.log file,

Welcome to Microsoft Telnet Service login: vtat password: *=============================================================== Welcome to Microsoft Telnet Server. *=============================================================== C:\Documents and Settings\vtat>cd c:\Documents and Settings\vtat\SCRIP +TS\SCL C:\Documents and Settings\vtat\SCRIPTS\SCL>

Thank you for your suggestion.

Replies are listed 'Best First'.
Re: PERL Telnet Times Out
by NetWallah (Canon) on May 31, 2010 at 06:13 UTC
    Please use <code> tags, as described in Writeup Formatting Tips.

    Your lines:

    $telnet->cmd("cd c:\\Documents and Settings\\vtat\\SCRIPTS\\SCL"); $telnet->waitfor('/.*\\n/');
    end up waiting for a literal "\n", since you have escaped the backslash.

    That will never come - try replacing the waitfor with:

    $telnet->waitfor('/\n/');
    The ".*" is unnecessary.

    Update: Have you considered using the free psexec, that does essentially the same thing more natively?

         Syntactic sugar causes cancer of the semicolon.        --Alan Perlis