If you want to return a variable containing the contents of the last issued command rather than have it print to the screen you could do something like...
#use diagnostics;
use strict;
use warnings;
sub SafeSystem
{
(my $command, my $error) = @_;
# Run the command, redirect standard and error output to log file
my $result = system($command . " 1>C:/output 2>&1");
# Read the output
open(SYS_OUT, "C:/output") or die "SafeSystem couldn't open C:/output";
my $output = join "", <SYS_OUT>;
close SYS_OUT;
# Did the command succeed?
if ($result ne 0) or die;
return $output;
}
# RUN A COMMAND BUT PRINT THE OUTPUT TO A VARIABLE RATHER THAN STDOUT
my $thecmd = "ping www.google.com";
my $res = SafeSystem($thecmd, "Error");