Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set up Strawberry Perl in MSYS?

I have Strawberry Perl and have msys Perl 5.6 removed.

Now perl will invoke Strawberry (due to PATH env) but how do I map the perl command in .pl or other Perl script files which have #!/bin/perl or #!/usr/bin/perl shebang lines?

I was thinking of making a hardlink to perl.exe in msys/bin or merge the whole Strawberry inside the msys directory, but I'm not sure.

like image 898
twinkletoes Avatar asked Dec 04 '09 10:12

twinkletoes


People also ask

Where is Strawberry Perl installed?

During installation, we recommend installing it in C:\Strawberry . This is the default for the MSI package. Connect your computer to the Internet so you are able download any required Perl modules from CPAN.

How do I know if Strawberry Perl is installed?

Just open a command prompt (in Windows, just type cmd in the run dialog and press Enter. If you're on a Mac or on Linux, open a terminal window). and press Enter. If Perl is installed, you receive a message indicating its version.


1 Answers

The solution is to create a symlink to the Strawberry Perl executable from within MSYS Tip of the hat to smaudet for his input:

First, remove or rename the Perl executables that the MSYS installation came with, if any (which the OP has already done); e.g.:

mv /usr/bin/perl /usr/bin/perl.msys 
mv /usr/bin/cpan /usr/bin/cpan.msys

Then create a symlink to Strawberry Perl's executable in its place:

ln -s /c/strawberry/perl/bin/perl.exe /usr/bin/perl

# Unfortunately, doing the same for `cpan` doesn't work directly, because
# Strawberry Perl's `cpan` executable is a *batch* file, `cpan.bat`, which
# cannot be directly invoked from MSYS.
# To invoke it from MSYS (assuming it is in the %PATH%):
#   cmd /c 'cpan.bat ...'
# With an explicit path:
#   cmd /c 'c:\strawberry\perl\bin\cpan.bat ...'
#
# Here's how to create a stub script that still allows invocation as 
# `cpan`:
echo 'cmd /c "C:\strawberry\perl\bin\cpan.bat $*"'>/usr/bin/cpan && chmod +x /usr/bin/cpan

Once the /usr/bin/perl symlink is in place, existing scripts with shebang lines #!/usr/bin/perl and #!/bin/perl will work again (the latter also works, because /bin and /usr/bin are effectively the same location in MSYS).

Note that scripts written with the more flexible shebang line #!/usr/bin/env perl do not need this, because env will directly find Strawberry Perl's perl.exe in the path.


Some background:

Unix-emulation environments such as MSYS and Cygwin do not respect Windows' %PATHEXT% variable to determine what executable to invoke a (non-binary) file with. In other words: filename extensions have no meaning with respect to execution there.

Instead, they solely go by whether the file has a shebang line:

  • If there is one, the executable specified in the shebang line is used.
  • If there is none, the default (POSIX-like) shell /bin/sh is used.
    • Thus, trying to invoke *.bat or *.cmd files directly fails, because they don't have a Unix shebang line and are therefore executed by /bin/sh rather than cmd.exe.

Unlike in Windows, this also works with (executable) files that have no filename extension at all.

like image 150
mklement0 Avatar answered Oct 22 '22 14:10

mklement0