Microsoft Windows .bat File

To turn a script into a program under Microsoft Windows, use the PL2BAT command. For example:

C:\SCRIPTS> pl2bat script.pl

The result is a script.bat file containing your Perl program. PL2BAT adds a few commands to the beginning of your script that run Perl and tell it to use the body of the batch file as the Perl script.

Listing B.1 contains the result of running PL2BAT on a simple Perl program.

Listing B.1. hello.bat
 @rem = '––*–Perl–*–– @echo off if "%OS%" == "Windows_NT" goto WinNT perl –x –S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 goto endofperl :WinNT perl –x –S %0 %* if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl if %errorlevel% == 9009 echo You do not have Perl in your PATH. if errorlevel 1 ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.