Christopher Peterson
Christopher Peterson

Reputation: 1027

How Do I Run a Perl Script from Cmd without typing "perl" in front of the script path?

For example perl C:\Projects\trunk\PcApps\BaseCamp\Test\smoketest.pl C:\Projects\trunk\PcApps\BaseCamp\Test\log.txt

Without the perl.

Upvotes: 4

Views: 4396

Answers (3)

slm
slm

Reputation: 16416

You can put this at the top of your perl script's file:

@SETLOCAL ENABLEEXTENSIONS
@c:\strawberry-perl-port\perl\bin\perl.exe -x "%~f0" %*
@exit /b %ERRORLEVEL%

#!perl

....perl program goes here...

You'll also need to change the extension of your script so that it's .cmd instead of .pl. The above trick runs the strawberry perl interpreter, calling it with the -x switch followed by "%~f0". This is the path to the .cmd script. The .cmd script will then exit once your perl program is complete.

The bit below the #!perl line is your actual perl program, which the perl.exe knows to skip to when this line runs:

@c:\strawberry-perl-port\perl\bin\perl.exe -x "path\to\my\perl.cmd" %*

Upvotes: 2

Meinersbur
Meinersbur

Reputation: 8071

There are a few programs that can convert your .pl file to .exe format:

After conversion, you may still need perl installed on your system, but the exe file finds the perl interpreter by itself. (Disclaimer: I did not try any of these)

Upvotes: 0

ThiefMaster
ThiefMaster

Reputation: 318518

Assign the .pl extension to the perl interpreter. It depends on your Windows version how you do that.

Depending on the perl installer you are using it might also provide you with an option to do so automatically.

Upvotes: 6

Related Questions