in reply to Capturing the output of nmap from within a Perl script
You effectively have print `...`. That can be simplified to system '...'. Furthermore, since that's the last command of the script, using exec '...' would be even more efficient.
Particularly if system is used, it wouldn't hurt to auto-flush STDOUT to make sure the header gets sent out at the right time.
No matter whether ``, system or exec is used, you might want to display what nmap sends to STDERR (if anything). Append 2>&1 to your command to do so.
#!/usr/bin/perl $| = 1; # Make sure the header gets sent first. print "Content-type: text/html\n\n"; exec "... 2>&1"; # We only get here if exec failed. my $error = "Error executing nmap: $!"; $error =~ s/&/&/g; $error =~ s/</</g; print("$error\n");
|
|---|