As mentioned, system doesn't return the output of the program you run (only its return code). You got lucky with that line of your program: whatever you execute via system shares STDOUT with your script, so the output of nmap happened to get printed to the web page at the right time (only not via your print statement).

You are on the right track using multi-arg system for safety. If you want to get data back from the call, you can use a magic open call. It's safer than using backticks (see above).

open(my $fh, '-|', 'nmap', $ip); ## may not be supported in your version of Perl, so ## also consider the equivalent: ## open(my $fh, '-|') or exec 'nmap', $ip; my $data = do { local $/; <$fh> }; close $fh;
Now you can do what you like with what's in $data -- replace newlines with <br>'s, print between <pre> tags, etc.

Update: BTW, the <pre> HTML tag makes the browser wrap according to your whitespace (instead of ignoring whitespace), as in my example code snippet. Search for it at your favorite HTML reference site and you will see what I mean.

Update II:Heh. Yeah, using text/plain will work too. But if you ever want to do anything with the data, get it from the program with the magic open call.

blokhead


In reply to Re: Text formatting a command in CGI by blokhead
in thread Text formatting a command in CGI by digitalx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.