$ perl --version
This is perl, v5.8.5 built for i386-linux-thread-multi

$ /usr/sbin/httpd -v
Server version: Apache/2.0.52 Server built: Jan 30 2007 09:56:53

$ cat /etc/redhat-release
Red Hat Enterprise Linux ES release 4 (Nahant Update 5)


From a Linux bash command line I invoke a1 with some command line args. a1 uses CGI param() to parse these args - no problems.

From the command line I invoke a2 with some command line args. a2 uses CGI param() to parse these args - no problems.

Change a1 so that it also invokes 'a2 with some command line args'. This instance of a2 can still parse args - no problems.

BUT invoked via a web browser a1 (still calls a2) can use param() to parse args but a2 seems to not be able to.

Here is a1.cgi

#!/usr/bin/perl -wl use CGI; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; use diagnostics; my $q = new CGI; my $v1 = $q->param('v1') || ''; my $hdr = "I am a1.cgi:"; print $q->header; print "$hdr v1=$v1<br>"; my $cmd = './a2.cgi v2=dog 2>&1'; print "$hdr cmd = $cmd<br>"; my $cmdOut = qx[$cmd]; print "$hdr cmdOut = <br>$cmdOut<br>";

Here is a2.cgi

#!/usr/bin/perl -wl use CGI; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; use diagnostics; my $q = new CGI; my $v2 = $q->param('v2') || ''; my $hdr = "&nbsp;&nbsp;I am a2.cgi:"; print "$hdr from param() v2=$v2<br>"; print "$hdr my cmd line args: @ARGV<br>";

Here is terminal session usage and output from a1.cgi # PASS

$ ./a1.cgi v1=box Content-Type: text/html; charset=ISO-8859-1 I am a1.cgi: v1=box<br> I am a1.cgi: cmd = ./a2.cgi v2=dog 2>&1<br> I am a1.cgi: cmdOut = <br>&nbsp;&nbsp;I am a2.cgi: from param() v2=dog +<br> &nbsp;&nbsp;I am a2.cgi: my cmd line args: v2=dog<br> <br>

Here is terminal session usage and output from a2.cgi # PASS

$ ./a2.cgi v2=dog 2>&1 &nbsp;&nbsp;I am a2.cgi: from param() v2=dog<br> &nbsp;&nbsp;I am a2.cgi: my cmd line args: v2=dog<br>

Here is browser output from web server url http://somewhere/a1.cgi?v1=box # FAIL

I am a1.cgi: v1=box I am a1.cgi: cmd = ./a2.cgi v2=dog 2>&1 I am a1.cgi: cmdOut = I am a2.cgi: from param() v2= I am a2.cgi: my cmd line args: v2=dog

As you can see, a1.cgi succeeds but a2.cgi fails to parse it's args via param(), when run by my 'simple' Apache web server.

I EXPECTED a2.cgi to sucessfully use param() regardless of my 3 invocation methods: 2 interactive + 1 apache.

This behavior is naively unexpected by me; can somebody please explain this mechanism?


In reply to CGI with nested apps, each calling param() to get their args by Zforgetaboutit

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.