I want to modify a Perl script to save the result to text file output.txt and open the results output.txt when task is done
I have tried used "use strict; use warnings;" and other methods but I keep getting an errors' The Last error was "Couldn't open output.txt"
#!/usr/bin/perl
use HTTP::Request;
use LWP::UserAgent;
system('cls');
system "color c";
print"\n";
print" |||||||||||||||||Robots scanner|||||||||||||||||||||";
print "\n";
print " Scan Your site Site\n\n Example: www.test.com \n\n-> ";
$site=<STDIN>;
chomp $site;
if($site !~ /http:\/\//) { $site = "http://$site/"; };
print "\n";
@path = ('robotx.txt','robots.txt','robot.txt','search',);
foreach $robots(@path){
$url = $site.$robots;
$req = HTTP::Request->new(GET=>$url);
$useragent = LWP::UserAgent->new();
$response = $useragent->request($req);
my $filename = 'report.txt';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
if ($response->is_success){
print ">>>>>>Robots Found !!!>>>: $url\n";
print $fh "out put has been generated by perl\n"; # THIS DOESN'T WORK THE report.txt is empty
print "done\n";
}else{
print "NotFound : $robots\n";
print "done\n";
# I want to open the file from windows explorer automatically here when its done
close $fh;
}
}
after running cmd as Admin , as you can see the report.txt file shows empty I expect to see the out put of the Response
I also want perl to open the report.txt ( without going to windows explorer and opening it manually by the user ) I want it automatically open when its done but I wasn't able to achieve that.
Thanks!