How do I set up Strawberry Perl in MSYS?
Asked Answered
O

3

8

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.

Octavie answered 4/12, 2009 at 10:42 Comment(1)
Please note that Strawberry Perl and MSYS Perl (/usr/bin/perl) probably isn't 100% compatible, especially when it comes to unixy stuff that the MSYS supports and Strawberry, which is native Windows, doesn't.Forward
W
4

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.

Wheelbase answered 22/7, 2015 at 22:49 Comment(0)
R
0

this works beautifully on the windows side of the computer, on the MSYS side you may need to

  • check the PATH environment variable and fix to include the strawberry perl access path

  • check the scripts for complete path in the shebang line (#!/usr/bin/perl). Those paths that are absolute in msys are in fact relative to the msys install directory in windows. you may need to "plug" your strawberry perl install to match or change the #! line

in the latter case my recommendation would be to use something like: #!env perl that checks the environment for the perl interpreter and alleviate the burden of dealing with /cygdrive/c/my/windows/path/not/visible/from/msys/otherwise

Rolland answered 31/7, 2010 at 21:2 Comment(0)
T
0

The correct shebang would be, eg. #!"C:/strawberry/perl/bin/perl.exe". However, you might prefer to run scripts explicitly with Perl rather than rely on the shebang, eg. perl script.pl or perl "C:\strawberry\perl\bin\cpan"

Note that Strawberry Perl doesn't get the shebang right for its own scripts, such as cpan and perldoc . Bug reported at https://rt.cpan.org/Public/Bug/Display.html?id=82837

Toddler answered 20/1, 2013 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.