tobbo has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm running into a strange problem when trying to execute nmap from Perl and fetching its output. The code looks like this:
my $cmd = "/usr/bin/nmap " . $self->settings . " -oX " . $self->report +file . " -v " . $self->target . " |"; close STDOUT; open(F, $cmd); my $buf = ""; while(<F>){ $buf .= $_; #do something here }

It works well if the settings attribute is "-sT", but not if it is "-sU". So obivously i thought that it's a nmap problem, but if I print out $cmd and execute it manually it works like a charm.

So my question is, could this be in any way a Perl problem?

Replies are listed 'Best First'.
Re: A weird problem while executing nmap and fetching its output
by Anonymous Monk on Apr 11, 2013 at 01:54 UTC

    It works well if the settings attribute is "-sT", but not if it is "-sU".

    What does that mean? -sU says it can be slow

    So my question is, could this be in any way a Perl problem?

    No

      Thanks for your reply!

      Well yes, -sU is slow, but on startup nmap prints a version info. Also, to be a bit more perl related, shouldn't while(<F>) read until an EOF?

      So I suspect that the command doesn't execute at all, even though it is syntactically correct (if I print out the command and paste it to the commandline, everything works perfectly).

      Is the whole open a command as a filehandle syntactic sugar for fork/pipe/execute so i can debug from there?

        > Is the whole open a command as a filehandle syntactic sugar for forkpipeexecute so i can debug from there?

        Well, like documented in open

        Cheers Rolf

        ( addicted to the Perl Programming Language)