When you are sending back data from a CGI, the FIRST THING that gets printed to STDOUT (which is where output from an external program is probably going to go) MUST be a properly-formed HTTP header. What seems to be happening here is that you make the call to system before you print your header, and so the first thing the webserver sees from your CGI is that external program's output.

One way around this problem is to use backticks (``) instead of system to execute your external program, although this is potentially less safe than the method you're currently using (since the string that appears in the backticks contains user-entered data, a nasty user might have your command execute something nasty).

my $output = `@args`;

the backticks redirect the output from the program to the variable you specify, and won't print them to STDOUT. If you decide to follow this advice be *sure* to use taint mode (add -T to the #! line) and untaint any user-entered data. See perldoc perlsec for more info.

Another way to do it that's less fraught with evil cr4X0r3r peril is to stick with your system call, but to redirect its output from STDOUT to somewhere else. If you want a log of your external program's output, append ">> external_command.log", or, if you don't care what the output is, "> dev/null") to your @args array. But use taint mode any time you're passing user-entered information to a shell.

HTH


In reply to Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: help with arrays by arturo
in thread help with arrays by Prince99

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.