The script works in debug mode and doesn't in run mode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lshilin
    New Member
    • Jul 2008
    • 1

    The script works in debug mode and doesn't in run mode

    Hi,

    here is my script:
    Code:
    #!/usr/local/bin/perl -d 
    use Net::Telnet; 
    
    my $res = ""; 
    
    my $ip = "10.120.7.95"; 
    my $user = "autorun"; 
    my $pass = "autorun"; 
    my $env = "stam"; 
    
    $tnt = Net::Telnet->new 
    ( Timeout => 60, 
    Prompt => '/.*(>|\$|\#|:)\s*/', 
    Errmode=>'die' ) 
    or $res = "ERROR: Could not initialize telnet: $!"; 
    
    $tnt->open ($ip) or $res .= "ERROR: Could not open connection to $ip: $!"; 
    
    $tnt->login($user,$pass) or $res .= "ERROR: Could not login to $ip: $user with $pass $!"; 
    
    $tnt->waitfor('/.*(>|\$|\#|:)\s*/'); 
    
    if ($res eq "") 
    { 
    &Cmd("ls >stam"); 
    } 
    if ($res =~ /Error/i) { print $res; } 
    
    
    sub Cmd { 
    print ">cmd\n"; 
    my $cmd = shift; 
    $tnt->buffer_empty; 
    print $tnt->cmd("cd autotest"); 
    print $tnt->cmd("setenv DISPLAY $ip:0.0"); 
    print $tnt->cmd($cmd); 
    print "<cmd\n"; 
    }
    If I run the script in debug mode, it works perfectly if even I give "c" option (it creates stam file), but if I try to run it without -d option, it doesn't create the file (no error messages)

    What is wrong? What is so different between running in debug mode?

    Thanks in advance
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Before we go trying to troubleshoot this, take the -d off so it is not in debug mode and add the following lines directly after the shebang line:

    Code:
    use strict;
    use warnings;
    Once you correct the errors reported by those two pragmas (which will be syntactical and the like), then we can get down to the real errors.

    Regards,

    Jeff

    Comment

    • p1qb0d
      New Member
      • May 2016
      • 2

      #3
      The same issue with the same module Net::Telnet.

      My script has "use strict; use warnings;". There are no errors in the script.

      It works under debugger and doesn't work in the flat run (the function getlines returns only one string instead of 25 under debugger).

      Perl 5.8.8 under CentOS 5.11, perl-Net-Telnet-3.03-5.

      The main excerpt:

      Code:
      @lines = $t->getlines(All => 0);

      Comment

      • RonB
        Recognized Expert Contributor
        • Jun 2009
        • 589

        #4
        Please don't hyjack an 8 year old thread. Start a new one and make sure it includes a short but complete script that demonstrates the problem and includes all errors/warnings it generates.

        Comment

        Working...