I'm trying to have a CGI script ("a.pl") call another CGI script ("b.cgi"), using system(). ("b.cgi" is used elsewhere; I just want to grab its (json) output and do things with it (using Capture::Tiny).

This works fine from the command line, but from the browser, "b.cgi" doesn't get the parameters that "a.pl" sends... or rather, the parms end up in @ARGV rather than $query->param.

Here's a minimal example. In this example, I'm not trying to process b.cgi's output in a.pl... I just want to show that b.cgi is not getting the parameters in $query->param.

a.pl

#!/usr/bin/perl use strict; use warnings; my @args = ("animal=duck", "vegetable=carrot"); system("/usr/bin/perl", "/tmp/b.cgi", @args);

and b.cgi:

#!/usr/bin/perl use warnings; use strict; use CGI; my $query = new CGI; print "Content-type: text/plain\n\n"; print "b.cgi query dump:\n"; print $query->Dump . "\n"; print "b.cgi argv dump:\n"; print join(',', @ARGV); print "\n";

Output when a.pl is invoked from the command line:

Content-type: text/plain b.cgi query dump: <ul> <li><strong>animal</strong></li> <ul> <li>duck</li> </ul> <li><strong>vegetable</strong></li> <ul> <li>carrot</li> </ul> </ul> b.cgi argv dump: animal=duck,vegetable=carrot

Output when a.pl is invoked through the browser:

b.cgi query dump: <ul></ul> b.cgi argv dump: animal=duck,vegetable=carrot

Is there some difference between a command-line invocation and a system() invocation?

I'm clearly misunderstanding something here... Any help you could give would be... well... helpful!

update: spelling


In reply to Invoking a cgi script from another cgi script using system() by bibliophile

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.