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 this excludes Windows XP.
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 in folder usr and then folder bin for the perl.exe executable.Default installation of Uniform Server executable path is:
For a default instalation of Uniform Server on C drive. Start at the top-level of C: drive, navigate the folder tree UniServerZ, core, perl finally look in in folder bin a 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 1: The mklink command is an internal command that is available in the following operating systems:
Note 2: The mklink command requires an elevated command prompt.
Creating a symbolic link to access the Perl executable
The above looks complex in reality is 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.
Create two new files link_create.bat and link_delete.bat in folder UniServerZ with the following content:
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 run as administrator) to create the symbolic link. You can now start the servers either as a standard program or service.