[Pi3web-users] CGI questions and answers
Brought to you by:
zimpel
|
From: <zi...@t-...> - 2002-05-25 07:58:00
|
Hi,
I got some questions regarding CGI execution via email and assume,
the answers are of general interest for the subscribers of this
list:
1.) Q: 500 Internal Server Error, when I tryo to execute a CGI. What's wrong?
========================================================================
The details of the error are:
"The server encountered an internal error while processing this request.
The following error messages were logged during this request:
[Sat May 25 01:48:15 2002 GMT] CGI: error executing CGI program system specific error code is '2'.
[Sat May 25 01:48:15 2002 GMT] CGI: DoExecCGIChild() failed. Error code is 2. Start of command line is 'perl
C:\Pi3Web\Cgi-Bin\test.cgi '."
A: The Win32 error no.2 means: The system cannot find the file specified.
The perl program is necessary to run the CGI script but can't be found.
Since perl is invoked without path, I assume, perl.exe isn't in your search
path. So either
- add perl.exe to the path - or -
- change the command line in the Pi3Web configuration into an
absolute path to perl.exe:
Search in the Pi3Web configuration file (Config.pi3) for line
CommandLineByExt .cgi="perl %p%q"
(within StandardCGI object) and change it accordingly, e.g.:
CommandLineByExt .cgi="c:\\Program files\\perl\\bin\\perl %p%q"
Consider the double backslash '\\' as path delimiter, because the backslash
is used for escape characters, as in character strings in the C programing
language.
2.) Q: I ported a perl CGI script from Unix to Win32 but it won't work. The
program calls a subroutine using the perl exec() function:
=======================================================================
if ($function1 =~ "rebar"){ exec
"/home/foo/cgi-bin/bar.cgi $CustomerNo";}
Is a special command format needed to call common routines from CGI files
when using Pi3Web on Windows?
A: No. The reason is:
On Unix, the shell is using the 'slashbang' line at the top of a script,
e.g. "#!/usr/bin/perl", in order to execute the script using the perl
interpreter.
On Windows this 'slashbang' line is ignored, thus the above call of exec()
will fail.
But an application can be associated with file extension .cgi in order to
execute the script from the command line without explicitely typing the
executable program.
The other way is, to invoke perl explicitely with the script name as a
parameter. A path must be given as a prefix, if perl.exe can't be found
in the search path:
if ($function1 =~ "rebar"){ exec
"perl /home/foo/cgi-bin/bar.cgi $CustomerNo";}
So finally, the solution is very similar to 1.)
Hint: Pi3Web 1.03 doesn't support CGI execution by associated file extensions,
but Pi3Web 2.0 does.
For the interested in web server security:
=========================================
What is the disadvantage of using exec() to invoke a CGI program directly
from another CGI instead of trigger a redirection of the client to the
other program by sending the appropriate response?
For the interested in perl CGI programing:
=========================================
What is the disadvantage of using exec() instead of using perl language
constructs like 'do', 'eval' or 'use' in order to include the code from
an external file as a subroutine or a perl module.
--
regards
Holger
TMTOWTDI - There's More Than One Way To Do It - Perl motto
----------------------------------------------------------
Holger 'zimpel' Zimmermann
----------------------------------------------------------
Wendishain
Germany
----------------------------------------------------------
http://home.t-online.de/home/zimpel/
http://pi3web.sourceforge.net/
mailto:zi...@t-...
----------------------------------------------------------
|