Zforgetaboutit has asked for the wisdom of the Perl Monks concerning the following question:
$ 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 = " 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> I am a2.cgi: from param() v2=dog +<br> 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 I am a2.cgi: from param() v2=dog<br> 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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI with nested apps, each calling param() to get their args
by Anonymous Monk on Oct 12, 2012 at 02:04 UTC | |
by Zforgetaboutit (Initiate) on Oct 12, 2012 at 14:34 UTC | |
by Anonymous Monk on Oct 13, 2012 at 15:48 UTC |