My question is regarding cgi. I wondered if I have a Perl script saved as a .cgi file, what is the actual mechanism that lets the server know it’s a Perl script and not something else? I know there is a #!/usr/local/bin/perl at the beginning of the source file but that’s also part of the Perl programing language, so the server has to know it’s a Perl script before it starts execution.
My question is regarding cgi. I wondered if I have a Perl script saved
Share
If the server is configured to recognize the
.cgisuffix, then it simply executes the file, probably using one of theexec*()functions.On a Unix-like system, if the file is a text file starting with
#!, then the system kernel itself will use that line to determine which interpreter to launch to run the file as a script.You can write CGI scripts in any interpreted language (Perl, Python, bash, sh, ruby, etc., etc.).
For that matter, you can use any executable file as a CGI
scriptprogram. If you compile, say, a C, C++, or Ada program to create an executable file, then install it in an appropriate directory with a.cgisuffix on the file name, the web server can execute it directly. It’s not commonly done, because scripting languages tend to be move convenient for this kind of thing, but the web server doesn’t care what kind of executable file it’s invoking, or how the kernel invokes it.(The details are likely to be a bit different on Windows, which usually uses the file extension to determine how to launch an executable.)