Hello Perlmonks. First time poster, first time script writer for Perl. I've got a sub that I've written here that I'm having some trouble getting output from a telnet connection.
sub telnet_connection{ my $targetHost = $_[0]; #my $uname = $_[1]; #my $pword = $_[2]; my @listOfCommands = @{$_[3]}; if($verbose){print "\t\tAttempting telnet connection to $targe +tHost\n"; } eval{ $telnet = Net::Telnet->new( Timeout=>5, Errmode=>'retu +rn', dump_log=>"dump_log.txt", input_log=>"input_log.txt"); $telnet->open($targetHost); $telnet->waitfor('/Username: $/i'); $telnet->print($username); $telnet->waitfor('/PASSCODE: $/i'); $telnet->print($password); $telnet->waitfor('/\>/'); #for(my $j=0; $j le scalar @listOfCommands; $j++) foreach my $command (@listOfCommands) { if($verbose) { print "\t\tClient: " . $targetHost +. " Command: $command\n"; } if($verbose) { print "\t\tExecuting command: $comm +and\n"; } my @output = $telnet->cmd($command); if($verbose) { print "OUTPUT:\n"; print @output; } logging($targetHost, \@output, "0"); } $telnet->close(); }; if($telnet->errmsg) { logging($targetHost,$telnet->errmsg,"1"); print $@; } }
This is a method I wrote that takes four arguments, the target of the telnet connection, username, password, and an array of commands. 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. 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 "":
Telnet to <targetIPAddress> Attempting telnet connection to <targetIPAddress> Client: <targetIPAddress> Command: who Executing command: who OUTPUT:
And I'm just not sure where to troubleshoot from here. I've looked through several of the stack overflow and perlmonks posts already on Telnet in Perl, but not much help was found there. When I use warnings or use strict, there aren't any issues in this sub.

In reply to Perl, Telnet, and No Output by DavisTasar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.