By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,710 Members | 1,970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,710 IT Pros & Developers. It's quick & easy.

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

P: 1
Hi,

here is my script:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl -d 
  2. use Net::Telnet; 
  3.  
  4. my $res = ""; 
  5.  
  6. my $ip = "10.120.7.95"; 
  7. my $user = "autorun"; 
  8. my $pass = "autorun"; 
  9. my $env = "stam"; 
  10.  
  11. $tnt = Net::Telnet->new 
  12. ( Timeout => 60, 
  13. Prompt => '/.*(>|\$|\#|:)\s*/', 
  14. Errmode=>'die' ) 
  15. or $res = "ERROR: Could not initialize telnet: $!"; 
  16.  
  17. $tnt->open ($ip) or $res .= "ERROR: Could not open connection to $ip: $!"; 
  18.  
  19. $tnt->login($user,$pass) or $res .= "ERROR: Could not login to $ip: $user with $pass $!"; 
  20.  
  21. $tnt->waitfor('/.*(>|\$|\#|:)\s*/'); 
  22.  
  23. if ($res eq "") 
  24. &Cmd("ls >stam"); 
  25. if ($res =~ /Error/i) { print $res; } 
  26.  
  27.  
  28. sub Cmd { 
  29. print ">cmd\n"; 
  30. my $cmd = shift; 
  31. $tnt->buffer_empty; 
  32. print $tnt->cmd("cd autotest"); 
  33. print $tnt->cmd("setenv DISPLAY $ip:0.0"); 
  34. print $tnt->cmd($cmd); 
  35. print "<cmd\n"; 
  36.  
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
Jul 16 '08 #1
Share this Question
Share on Google+
3 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
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
Jul 16 '08 #2

P: 2
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:

Expand|Select|Wrap|Line Numbers
  1. @lines = $t->getlines(All => 0);
May 25 '16 #3

Expert Mod 100+
P: 589
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.
May 25 '16 #4

This discussion thread is closed

Replies have been disabled for this discussion.