473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Calling cgi from cgi thru 'system' function. Different behaviour on browser v/s cmd line

Hi

Im having trouble with the following code that seems to be behave
differently when called from the browser as opposed to the command
line. The calling script is a cgi that forks, with the child trying to
call another cgi script and pass arguments to it. It works fine from
the command line, and calls the required script and passes the
arguments correctly. However, when it is run on the browser, it calls
the script but does not pass the arguments to it.
The called script (included) is also a cgi, set up to accept
parameters via the param function. It accepts the parameters when the
calling script is run on the command line, but not when the calling
script is run on the browser.

I have also tried putting a '?' between the script name and the
arguments to get the "script.cgi?argument=1" format, and that didnt
work either.

Im not sure if the problem is in the system call, the use of CGI in
the called script, or somewhere else entirely. Any suggestions would
be extremely helpful...

Thanks in advance
Shailan

#### Calling script

if (my $pid = fork){
while (waitpid(-1,&WNOHANG) != $pid){
print ".";
sleep 2;
}

print qq{
</body>
</html>
};

exit;
}
else {
die "Cannot fork: $!\n" unless defined $pid;

#### Call the actual processing script.

print "Executing $program $args\n";
! system("perl", "$program", $args) or die "Call failed: $!";
#print $output;

exit;
}

#### End Calling script
#### Called script

#!/usr/local/bin/perl

use CGI;
use strict;

my $query = new CGI;
my $sleep_time = $query->param("sleep");
my @params = $query->param;

print "Content-type: text/html\n\n";
print qq{
<html>
<head><title>INF</title>
</head>
<body>
@params
};

for (my $i = 0; $i < 10; $i++){
print "Working\n";
sleep $sleep_time;
}
print qq{
Sleep time was $sleep_time<br>
Finished
</body>
</html>
};

exit;
#### End Called script
Jul 19 '05 #1
2 4720
The problem is the called CGI program is no longer a "CGI". It is just a
regular program. You should look for the parameters from the command line,
instead of using $query->param, which fetches the param from env var
QUERY_STRING, of course it is empty in this case.

So try to get the param from command line, like regular program in you
called "CGI" program like this,

$ARGV[0] $ARGV[1] ....

You will be doing fine

"Shailan" <sh*****@ureach.com> wrote in message
news:f8**************************@posting.google.c om...
Hi

Im having trouble with the following code that seems to be behave
differently when called from the browser as opposed to the command
line. The calling script is a cgi that forks, with the child trying to
call another cgi script and pass arguments to it. It works fine from
the command line, and calls the required script and passes the
arguments correctly. However, when it is run on the browser, it calls
the script but does not pass the arguments to it.
The called script (included) is also a cgi, set up to accept
parameters via the param function. It accepts the parameters when the
calling script is run on the command line, but not when the calling
script is run on the browser.

I have also tried putting a '?' between the script name and the
arguments to get the "script.cgi?argument=1" format, and that didnt
work either.

Im not sure if the problem is in the system call, the use of CGI in
the called script, or somewhere else entirely. Any suggestions would
be extremely helpful...

Thanks in advance
Shailan

#### Calling script

if (my $pid = fork){
while (waitpid(-1,&WNOHANG) != $pid){
print ".";
sleep 2;
}

print qq{
</body>
</html>
};

exit;
}
else {
die "Cannot fork: $!\n" unless defined $pid;

#### Call the actual processing script.

print "Executing $program $args\n";
! system("perl", "$program", $args) or die "Call failed: $!";
#print $output;

exit;
}

#### End Calling script
#### Called script

#!/usr/local/bin/perl

use CGI;
use strict;

my $query = new CGI;
my $sleep_time = $query->param("sleep");
my @params = $query->param;

print "Content-type: text/html\n\n";
print qq{
<html>
<head><title>INF</title>
</head>
<body>
@params
};

for (my $i = 0; $i < 10; $i++){
print "Working\n";
sleep $sleep_time;
}
print qq{
Sleep time was $sleep_time<br>
Finished
</body>
</html>
};

exit;
#### End Called script

Jul 19 '05 #2
Thanks Alex...that clears it up.

"Alex Zeng" <al*******@digi-go.com> wrote in message news:<eN********************@comcast.com>...
The problem is the called CGI program is no longer a "CGI". It is just a
regular program. You should look for the parameters from the command line,
instead of using $query->param, which fetches the param from env var
QUERY_STRING, of course it is empty in this case.

So try to get the param from command line, like regular program in you
called "CGI" program like this,

$ARGV[0] $ARGV[1] ....

You will be doing fine

"Shailan" <sh*****@ureach.com> wrote in message
news:f8**************************@posting.google.c om...
Hi

Im having trouble with the following code that seems to be behave
differently when called from the browser as opposed to the command
line. The calling script is a cgi that forks, with the child trying to
call another cgi script and pass arguments to it. It works fine from
the command line, and calls the required script and passes the
arguments correctly. However, when it is run on the browser, it calls
the script but does not pass the arguments to it.
The called script (included) is also a cgi, set up to accept
parameters via the param function. It accepts the parameters when the
calling script is run on the command line, but not when the calling
script is run on the browser.

I have also tried putting a '?' between the script name and the
arguments to get the "script.cgi?argument=1" format, and that didnt
work either.

Im not sure if the problem is in the system call, the use of CGI in
the called script, or somewhere else entirely. Any suggestions would
be extremely helpful...

Thanks in advance
Shailan

#### Calling script

if (my $pid = fork){
while (waitpid(-1,&WNOHANG) != $pid){
print ".";
sleep 2;
}

print qq{
</body>
</html>
};

exit;
}
else {
die "Cannot fork: $!\n" unless defined $pid;

#### Call the actual processing script.

print "Executing $program $args\n";
! system("perl", "$program", $args) or die "Call failed: $!";
#print $output;

exit;
}

#### End Calling script
#### Called script

#!/usr/local/bin/perl

use CGI;
use strict;

my $query = new CGI;
my $sleep_time = $query->param("sleep");
my @params = $query->param;

print "Content-type: text/html\n\n";
print qq{
<html>
<head><title>INF</title>
</head>
<body>
@params
};

for (my $i = 0; $i < 10; $i++){
print "Working\n";
sleep $sleep_time;
}
print qq{
Sleep time was $sleep_time<br>
Finished
</body>
</html>
};

exit;
#### End Called script

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Pjotr Wedersteers | last post by:
Hi, When I include a script in my html I don't get any output back in the calling page. The script is on a remote location for the html page. Example given: myscript.php: <?PHP echo...
1
by: Roger | last post by:
Are these two features available in VS.Net 2003 at all (maybe different keys)... F4 to go thru find-in-files search results (just like you F4 to go thru build errors). In VC6, if output window...
18
by: Simula | last post by:
I am developing an HTML javascript application and I want to preserve state in a way that can be book-marked. I chose HTML anchors as a means of preserving state. When the application changes...
2
by: Phil Stanton | last post by:
When designing a new form or report, the Default ForeColor is often something like -2147483640 which is the colour of Windows text (possibly black) and the default backColor is -2147483643...
5
by: sugaray | last post by:
Right now, the code I wrote below seems works fine, i know it's definitely not the best solution, so if there are better solutions to eschew from using goto statements to jump out of multiple loops...
9
by: kernelxu | last post by:
hi,everybody. I calling function setbuf() to change the characteristic of standsrd input buffer. some fragment of the progrem is: (DEV-C++2.9.9.2) #include <stdio.h> #include <stdlib.h> int...
2
by: | last post by:
I have a breakpoint in an aspx page that I'm using to try to trap some code to see what's going on. I'm translating a page that is working in a traditional ASP page, which takes several session...
0
by: Cleo | last post by:
Hi, I am trying to call a WebService Method written in Weblogic from VB.NET and I am getting the following error. I am using SOAP Caal s from VB.NET. Please find the wsdl file and my code. ...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.