How to run CGI scripts written in Perl on Windows?
For testing purposes while building websites I’m using a web server (Apache) installed on the local computer on which I installed Windows. At some point, I needed to run on it the one available on the Internet CGI script, which was written in Perl. But in spite of that I had Perl installed which I downloaded from ActiveState and properly configured Apache (Options ExecCGI), the script didn’t work – server was showing error 500 (Internal Server Error), and server logs had two error messages: “The system can not find the specified path.: couldn’t spawn child process” and “The system can not find the path specified.: couldn’t create child process “. As it turned out, the server could not find the Perl interpreter. It was looking for it where the first line of the CGI script was pointing, which is in /urs/bin/perl. Because there isn’t such path in Windows, so there is no wonder that the script could not run.
The first solution that I tried was to replace Unix to Windows file paths – instead of /usr/bin/perl I put the path to the directory where I had Perl installed on Windows. The solution proved to be effective – the script launched. Despite this, however, I decided to look for another solution, because I wanted to have one version of the script, which will run both on Unix and Windows.
Fortunately, in Windows, you can also use slash “/” in the paths to files. It is possible to use the paths that start with slash – this refers to the path to the root directory of the current hard disk drive. In the case of CGI scripts running on Apache server the current drive is the one where server is installed on. The solution was therefore to create a directory on a disk where I installed the server /usr/bin and copy the file perl.exe there from ActiveState Perl directory. After this simple action I could use CGI scripts written in Perl also on Windows, without the need to modify them.