This page covers running Perl scripts with Unix Shebang unmodified on Windows. It allows you to easily transfer scripts between Windows and Unix systems, and to run scripts from third parties that use a Unix Shebang.
Note: The implementation is for a fixed installation of Uniform Server running either as a standard program or as a service on a modern version of Windows that supports symbolic links.
Shebang interpreter directive
The syntax of a Shebang (interpreter directive) is as follows: #! interpreter [optional-arg]
Note: The forward slash is shorthand meaning "top-level of the current drive". For example, to find the perl.exe executable on C drive, start at the top-level of C: drive, look in folder usr and then folder bin for the perl.exe executable.Uniform Server format:
For a default installation of Uniform Server on C drive, start at the top-level of C: drive, navigate the folder tree UniServerZ, core, perl, and finally look in folder bin for the perl.exe executable.
Note: In both cases, the .exe extension is optional; generally, the Unix Shebang excludes this extension.
From the above example, a Unix Shebang will not find the perl.exe executable on a default installation of Uniform Server. The path /usr/bin/perl does not exist. What is required is to map the Unix Shebang to the real path C:/UniServerZ/core/perl/bin/perl.exe. This is achieved using a symbolic link.
C:/usr/bin/perl.exe - Unix path C:/UniServerZ/core/perl/bin/perl.exe - Uniform Server path
Starting from right to left, remove common elements to give:
C:/usr - Unix path C:/UniServerZ/core/perl - Uniform Server path
Note: The mklink command requires an elevated command prompt.
Creating a symbolic link to access the Perl executable
The above looks complex; in reality, it is quite simple. All that is required is to map folder usr to folder path C:/UniServerZ/core/perl using the following command line:
mklink /D usr C:\UniServerZ\core\perlServer relocation
Uniform Server is portable and can be moved to a different location (either to a different folder or hard drive) by copying folder UniServerZ and all its content to the desired location. However, you must remember to adjust the path accordingly in the symbolic link. This inconvenience is avoided by using two batch files.Batch files
The following two batch files allow you to easily create and delete a symbolic link to access the Perl executable.
Two new files (link_create.bat and link_delete.bat) are created in folder UniServerZ upon Perl installation:
Test 1 - Apache running as a standard program
Test 2 - Apache running as a service
Note: To remove the link, double-click on file link_delete.bat
You can move Uniform Server to a new location. First, run link_delete.bat to remove the symbolic link. Move folder UniServerZ and all its content to the new location. Run link_create.bat (right-click file link_create.bat and select Run as administrator) to create the symbolic link. You can now start the servers either as a standard program or service.