title: Perl, telnet, and output
body: <p>I'm having trouble finding out why my perl script isn't handling output appropriately.</p>
  
  <p>So, the code (<strong>Updated based on suggested changes</strong>):</p>
  
  <pre><code>sub telnet_connection{
  
  
      my $targetHost = $_[0]; 
      #my $uname = $_[1];
      #my $pword = $_[2];
      my @listOfCommands = @{$_[3]};
  
      if($verbose){print "\t\tAttempting telnet connection to $targetHost\n"; }
  
      eval{
              $telnet = Net::Telnet-&gt;new( Timeout=&gt;5, Errmode=&gt;'return', dump_log=&gt;"dump_log.txt", input_log=&gt;"input_log.txt");
              $telnet-&gt;open($targetHost);
              $telnet-&gt;waitfor('/Username: $/i');
              $telnet-&gt;print($username);
              $telnet-&gt;waitfor('/PASSCODE: $/i');
              $telnet-&gt;print($password);
              $telnet-&gt;waitfor('/\&gt;/');
  
  
              #for(my $j=0; $j le scalar @listOfCommands; $j++)
              for my $command (@listOfCommands)
              {
                  if($verbose) { print "\t\tClient: " . $targetHost . " Command:  $command\n"; }
                  if($verbose) { print "\t\tExecuting command: $command\n"; }
                  my @output = $telnet-&gt;cmd($command);
  
                  if($verbose) 
                  { 
                      print "OUTPUT:\n";
                      print "@output\n"; 
                  }
                  logging($targetHost, \@output, "0");
              }
              $telnet-&gt;close();
          };
          if($telnet-&gt;errmsg)
          {
              logging($targetHost,$telnet-&gt;errmsg,"1");
              print $@;
          }
  }
  </code></pre>
  
  <p>This is a method I wrote that takes four arguments, the target of the telnet connection, username, password, and an array of commands. <em>For right now, I'm just using the global usernames and passwords ($username $password respectively) because there was an issue with something else. $verbose is a flag that I pass, and in this case it's set to true. logging is another method I wrote to handle output accordingly, but with $verbose being true, I should see it on the console.</em> The code is able to authenticate, and run the commands, but my output isn't present. When I check the dump_log and input_log, the raw (and formatted) text is present, and shows that I'm actually executing the commands and seeing the output, yet, when I try to check the output, it comes back with a "":</p>
  
  <pre><code>Telnet to &lt;targetIPAddress&gt;
          Attempting telnet connection to &lt;targetIPAddress&gt;
          Client: &lt;targetIPAddress&gt; Command:  who
          Executing command: who
  OUTPUT:
  </code></pre>
  
  <p>And I'm just not sure where to troubleshoot from here. I've looked through several of the stack overflow posts already on Telnet in Perl, but not much help was found there. </p>