http://qs321.pair.com?node_id=1111861

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

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