views:

1361

answers:

6

I currently use Strawberry Perl as my primary Perl distribution. However, I have some applications that make Perl calls through cygwin. These generally fail because they are calling the version of Perl that was packaged with cygwin, and only looking in cygwin's lib folders. How can I modify my cygwin environment to call Strawberry Perl (and use the C:/strawberry/perl/lib dirs) instead?

A: 

I don't have my cygwin machine nearby so I can't test this, but perhaps you can front-end the perl command with a script: go to /bin under cygwin and move the perl.exe there to something else like perl-org.exe, then set up a shell script that execs your other perl with the same arguments.

Shannon Nelson
+6  A: 

If you remove Perl from cygwin using the setup program it will use Strawberry Perl by default.

If you are unable to remove Perl from cygwin, you can create a symbolic link to the Perl executable from Strawberry.

From a cygwin shell, use the following set of commands:

$ mv /usr/bin/perl /usr/bin/perl-cygwin
$ ln -s /cygdrive/c/strawberry/perl/bin/perl.exe /usr/bin/perl

This is assuming you used the default Strawberry Perl installer. Update your perl.exe location accordingly if you have it installed somewhere else.

Check to make sure the link is working properly by checking the Perl version:

$ perl -v

It should say This is perl, (version) built for MSWin32-x86-multi-thread (or similar) and not built for cygwin-thread-multi-64int.

cowgod
worked like a charm! Thanks!
Sam Johnson
A: 

You can change your PATH to put the Strawberry directories first. Strawberry tries to be nice by putting its directories at the end of the PATH. If you installed from the .zip file, however, it didn't change the PATH at all.

You could move /usr/bin/perl, but that's a bad idea since it breaks when cygwin tries to update what it thinks is its perl. I just had that happen to me this week and used to happen to me on my Mac until I stopped playing with the system setup and installed my own stuff completely separate.

brian d foy
A: 

This is probably not a preferred solution, but you should be able to modify the #! line:

#!/cygdrive/c/strawberry/perl/bin/perl5.10.0

I always refer to an explicit location and installation of perl, rather than relying on what is in /usr/bin.

skiphoppy
A: 

I have two scripts that I use to modify the first line of Perl scripts to whichever Perl is first in my path: rightperl hardcodes to the Perl that is first in my $PATH now, envperl will change the line to #!/usr/bin/env perl so the Perl to use is only picked at the time the script is invoked. Works really well under Cygwin (and from a Unix shell in general).

reinierpost
+1  A: 

One good thing I can add is that if you get the right perl to come first in the path, it should handle site-specific CPAN modules you may have installed with strawberry perl running in a CMD shell.

"which perl" is your friend.

If you had trouble with this, you could set the PERL5LIB environment variable, but it shouldn't be necessary.

I still pass in DOS-style file paths as parameters into the perl script, i.e. "d:\data\myfile.txt", not "/cygdrive/d/data/myfile.txt". So oddly enough, this mix of path notation works:

bash> /cygdrive/d/scripts/myscript.pl d:\data\myfile.txt

Ben