1

problem: I cannot run a perl script using an absolute path. I can list it with the same path, but only execute it when using a relative path!

the output of my Cygwin terminal will make this problem obvious

Here I try to execute the script with an absolute path - it fails:

LPI@Reboot /cygdrive/c/Users
$ /cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl
Can't open perl script "/cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl": No such file or directory

Here I list it using the same absolute path - it works, the file is there:

LPI@Reboot /cygdrive/c/Users
$ ls /cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl
/cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl

Here I try and execute it using a path relative to my current directory /cygdrive/c/Users:

LPI@Reboot /cygdrive/c/Users
$ LPI/3DSiteSoftware/Code/Scripts/path_name.pl
USAGE: LPI/3DSiteSoftware/Code/Scripts/path_name.pl -p|-n <string>

Does anyone know why the first example is not working? I'm getting stumped! thanks for any advice.

2
  • What does ls -l /cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl return? Commented Jun 20, 2014 at 1:23
  • What's the output of head -n 1 LPI/3DSiteSoftware/Code/Scripts/path_name.pl? Commented Jun 20, 2014 at 1:28

1 Answer 1

3

I'm going to guess that you're using a non-Cygwin version of Perl (like Strawberry Perl or ActivePerl) that doesn't know anything about /cygdrive/ paths. You can confirm this by running perl -v. If it says built for MSWin32 then it's not Cygwin Perl.

So when you run

/cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl

Bash runs

perl.exe /cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl

but Perl looks for

C:/cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl

and doesn't find it.

When you run

LPI/3DSiteSoftware/Code/Scripts/path_name.pl

Bash runs

perl.exe LPI/3DSiteSoftware/Code/Scripts/path_name.pl

Perl combines that with your current directory of C:\Users, and gets

C:\Users\LPI/3DSiteSoftware/Code/Scripts/path_name.pl

(Perl doesn't care about mixed slashes on Windows).

The simplest solution is probably just to install Cygwin's version of Perl, which will understand Cygwin paths. Or you could write some sort of shim perl that converts the script name to a Windows path and invokes the real perl.exe.

Another possibility might be to use NTFS symbolic links to create the /cygdrive directory on each of your volumes (i.e., create a C:\cygdrive directory, and make C:\cygdrive\c a symlink to C:\, C:\cygdrive\d a symlink to D:\, etc.). But you'd have to do that on any drive that might be current when you invoke a Perl script.

Sign up to request clarification or add additional context in comments.

3 Comments

Other option: perl "$( cygpath --dos /cygdrive/.../path_name.pl )"
Installing cygwin's Perl (if it's not already) isn't sufficient. It's a question of adjusting the shebang too.
Yes I'm using ActivePerl - I'll try and switch - Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.