Perl Shebang for Windows

Unix-heads are used to perl scripts begining with #!/usr/bin/perl (the so-called, “shebang” notation). This is a feature I’ve always missed on Windows.

Thanks to Google’s filetype keyword, I found I a solution.


@rem = '
@echo off
\path\to\perl\perl.exe %0.cmd %*
exit /B %ERRORLEVEL%
';
print "Hello Perl World!";

The one caveat here is that you must name your file with the .cmd extension.

Update: Changed to return a proper errorlevel. Thanks, Kevin.

Advertisements

1 Response to “Perl Shebang for Windows”


  1. 1 Kevin Frei December 8, 2005 at 1:49 pm

    try exit /B%ERROR_LEVEL% instead of exit /B0 to get the return value passed back properly.


Comments are currently closed.




%d bloggers like this: