Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl CGI exec command

Status
Not open for further replies.

tecknick

Programmer
Aug 23, 2002
7
AU
Hey

I am having trouble getting the exec() command used within a perl script to be executed via a web browser.

Code:
if statement is true
    { 
    exec("search.cgi");
    }
else
    {
    &Login;
    }

The above is a snippet. When run in Unix, if the statement is true, the search script is executed. When I try through the web browser, I get an internal server error.

?????????

If the condition is true, I want the current script to halt execution and execute the new script.

Any help? I am new to the CGI thing.

Thanx

Tecknick
 
The problem with exec() in this case is that it kills the current program running, and starts up a new one. When the requested script dies, the server thinks the connection is done with.

You can try two other methods that may work:

system("perl search.cgi");
exit;

OR

use CGI;
my $j = new CGI;
print $j->redirect("search.cgi");

The first one uses the system command, which doesn't kill the script. After the 'called' program is finished executing, control is returned to the 'calling' perl program. After that you wish to exit, I presume.

The second one uses Lincol Stein's CGI.pm module (comes with standard distribution) and creates an Object of the CGI class. Then we use the redirect method of that object which outputs special headers to the user's browser redirecting the browser itself to request the search.cgi program.

Hope this helps.

--jim

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top