N
niall.macpherson
I'm using Net::Telnet for the first time.
I would like to run a command on a remote windows machine and have been
experimenting with the Net::Telnet module.
The attached test code seems to work - It just executes 'dir' on the
remote machine and redirects the output to the file.
However I want to be able to capture the output from the remote command
I am running directly rather than have to write it to an intermediate
file.
I thought I could replace this
my $cmdstring = q(dir > C:/testtelnet/diroutput.txt); ## How do I
capture output here ??
my $output = $tel_conn->cmd (String => $cmdstring);
with
my $cmdstring = q(dir);
my @output = $tel_conn->cmd (String => $cmdstring);
but I just get an array containing an empty string.
Can someone point out where I am going wrong ? TIA
------------------------------------------------------------------------------------------------------------------------------------
use strict;
use warnings;
use Net::Telnet;
use Data:umper;
if($#ARGV != 1)
{
print STDERR "\nUsage $0 <username> <password>";
exit(-1);
}
my $timeout = 10;
my $prompt = '/C:\\\\/i';
my $tel_conn = new Net::Telnet ( Timeout => $timeout,
## valid values are 'die' or 'return'
Errmode => 'return', ## TODO check this
Prompt => $prompt,
Dump_Log => 'C:\TelnetDump.txt',
Input_Log => 'C:\TelnetInput.txt',
Option_Log => 'C:\TelnetOption.txt'
);
my $hostname = 'lonsdbmis';
$tel_conn->open($hostname);
my ($username, $passwd) = @ARGV;
$tel_conn->login($username, $passwd);
my $cmdstring = q(dir > C:/testtelnet/diroutput.txt); ## How do I
capture output here ??
my $output = $tel_conn->cmd (String => $cmdstring);
#my $cmdstring = q(dir);
#my @output = $tel_conn->cmd (String => $cmdstring); ## This returns
array containing empty string
print Dumper 'Output from dir command';
print Dumper $output;
#print Dumper \@output;
$tel_conn->close();
exit(0);
I would like to run a command on a remote windows machine and have been
experimenting with the Net::Telnet module.
The attached test code seems to work - It just executes 'dir' on the
remote machine and redirects the output to the file.
However I want to be able to capture the output from the remote command
I am running directly rather than have to write it to an intermediate
file.
I thought I could replace this
my $cmdstring = q(dir > C:/testtelnet/diroutput.txt); ## How do I
capture output here ??
my $output = $tel_conn->cmd (String => $cmdstring);
with
my $cmdstring = q(dir);
my @output = $tel_conn->cmd (String => $cmdstring);
but I just get an array containing an empty string.
Can someone point out where I am going wrong ? TIA
------------------------------------------------------------------------------------------------------------------------------------
use strict;
use warnings;
use Net::Telnet;
use Data:umper;
if($#ARGV != 1)
{
print STDERR "\nUsage $0 <username> <password>";
exit(-1);
}
my $timeout = 10;
my $prompt = '/C:\\\\/i';
my $tel_conn = new Net::Telnet ( Timeout => $timeout,
## valid values are 'die' or 'return'
Errmode => 'return', ## TODO check this
Prompt => $prompt,
Dump_Log => 'C:\TelnetDump.txt',
Input_Log => 'C:\TelnetInput.txt',
Option_Log => 'C:\TelnetOption.txt'
);
my $hostname = 'lonsdbmis';
$tel_conn->open($hostname);
my ($username, $passwd) = @ARGV;
$tel_conn->login($username, $passwd);
my $cmdstring = q(dir > C:/testtelnet/diroutput.txt); ## How do I
capture output here ??
my $output = $tel_conn->cmd (String => $cmdstring);
#my $cmdstring = q(dir);
#my @output = $tel_conn->cmd (String => $cmdstring); ## This returns
array containing empty string
print Dumper 'Output from dir command';
print Dumper $output;
#print Dumper \@output;
$tel_conn->close();
exit(0);