I have been developing my scripts using Strawberry perl installed in C: drive (5.20.11) I've now installed the portable version on my USB stick. (5.28.xx) Whatever I try, it ALWAYS reverts to the primary version in C:

I know this as I put this at the top of the script (print $];) and always comes back as 5.2011.

I tried using a modification of the standard Strawberry bat file that starts the USB version of perl

@echo off
if not "%1" == "/SETENV" setlocal
set PATH=%~dp0perl\site\bin;

... thinking that would set the path to the required version, but still loads from C: drive !!

I tried the above path line as the first line of script,(no ball -fact the script will run without ANY shebang?)

Not to mention the shortcut link which uses "explorer.exe" so I can add the "..\script_path\sample.pl" in the Target field ... (that method doesn't work with cmd.exe in target. With a link after the program name, all it does is open CMD with directory set to "RunMe") which then complains that "sample.pl" is not a command or script. (Even tried "perl sample.pl" ... as you would enter in CMD will not work)

OK,so end user will not have two versions running ... but that don't help me any !

(After lunch, will try changing name of C:Strawberry so it can't be found at boot up ... but that seems a little drastic!)

NB: On stick, it's "strwawberry/perl/bin/perl.exe",the other is "R:\School Programs\sample.pl", "School Programs\sample.bat" and shortcut is "R:\RunMe\sample.bat" in the target field.(Start In is empty ... I can't set this as Drive letter will vary from user to user !)

Totally lost !!

2 Answers 2


However you invoke the batch file, simply running sample.pl

  • doesn't guarantie the current dir IS the batch files folder %~dp0
  • replacing the system variable path will cut you off from any other needed exeutables
  • uses the association/file type resp. "hklm\software\classes\.pl" from the registry to identify the program to execute the .pl file with and NOT your version.

So better run your perl.exe and pass sample.pl as an argument.
EDIT: changed path to perl.exe due to @JosefZs hint

@echo off
if not "%~1" == "/SETENV" setlocal
set "PATH=%~d0\strawberry\perl\bin;%path%"
"%~d0\strawberry\perl\bin\perl.exe" "%~dp0sample.pl"
  • 1
    Maybe %~d0\strwawberry\perl\bin\perl.exe instead of %~dp0perl\site\bin\perl.exe considering the OP's note NB: On stick, it's "strwawberry/perl/bin/perl.exe"?
    – JosefZ
    Apr 7, 2019 at 14:53
  • @JosefZ Yes you are right, I overlooked the NB
    – LotPings
    Apr 7, 2019 at 15:07
  • Ahhh ... that's one glaring error I didn't see, the extra 'site\' folder that doesn't exist !! Apr 7, 2019 at 16:40
  • Thanks LotPings. (Funnily enough, I just thought of starting perl each time -and modifying the portable bat file - when I want to start a new script ... rather than have it running in background, and then passing items to it) I'm used to simply calling a script via browser. So - on a tangent - whilst the Apache server runs all the time, when you call a perl script, does it run and then terminate, to start afresh when it next encounters next shebang? Apr 7, 2019 at 16:48
  • 1
    Tried this from shortcut in "RunMe" (%windir%\explorer.exe "..\School_Programs\sample.bat") ... and it opens up "My Documents on C: drive to select a file !!!! "R:\RunMe\shortcut" "R:\School_Programs\sample.bat" and "sample,pl" Apr 7, 2019 at 17:36

After a lot of trial and error, I found that (so far) it seems to work without the use of a batch script, using a CMD shortcut, and relative links to the location of the script. So the command I am now using in the "Target" field is C:\Windows\System32\cmd.exe \k "..\strawPerlPort\perl\bin\perl.exe ..\School_Programs\sample.pl"

It does make rather long link in the title bar of the CMD title bar, but at least it works as neither "Target" or "Start In" accept relative paths or "%~dp0" (My theory is CMD.exe is loading perl, and in turn, perl is loading the script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.