无法使用绝对路径执行Perl脚本

无法使用绝对路径执行Perl脚本

本文介绍了Bash:无法使用绝对路径执行Perl脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我无法使用绝对路径运行perl脚本.我可以使用相同的路径列出它,但是只有在使用相对路径时才执行它!

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!

我的Cygwin终端的输出将使此问题显而易见

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

在这里,我尝试使用相对于当前目录/cygdrive/c/Users的路径执行它:

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.

推荐答案

我猜测您使用的是非Cygwin版本的Perl(例如Strawberry Perl或ActivePerl),它对/cygdrive/路径.您可以通过运行 perl -v 来确认.如果显示 MSWin32内置,则它不是Cygwin Perl.

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.

所以当你跑步

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

重击奔跑

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

但是Perl寻找

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

但找不到它.

跑步时

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

重击奔跑

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

Perl将其与您当前的 C:\ Users 目录结合在一起,并获取

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

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

(Perl不在乎Windows上的混合斜杠).

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

最简单的解决方案可能只是安装Cygwin的Perl版本,该版本将了解Cygwin路径.或者,您可以编写某种填充程序 perl ,将脚本名称转换为Windows路径并调用真正的 perl.exe .

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.

另一种可能是使用 NTFS符号链接创建/cygdrive 目录(即,创建一个 C:\ cygdrive 目录,并使 C:\ cygdrive \ c 成为指向 C的符号链接:\ C:\ cygdrive \ d D:\ 的符号链接等).但是,您必须在调用Perl脚本时在任何当前驱动器上执行此操作.

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.

这篇关于Bash:无法使用绝对路径执行Perl脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:49