Bash:无法使用绝对路径执行perl脚本?
问题:我无法使用绝对路径运行perl脚本。我可以用相同的路径列出它,但只能在使用相对路径时执行它 我的Cygwin终端的输出会使这个问题变得明显 在这里,我尝试以绝对路径执行脚本-它失败:Bash:无法使用绝对路径执行perl脚本?,perl,bash,Perl,Bash,问题:我无法使用绝对路径运行perl脚本。我可以用相同的路径列出它,但只能在使用相对路径时执行它 我的Cygwin终端的输出会使这个问题变得明显 在这里,我尝试以绝对路径执行脚本-它失败: 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/
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
在这里,我使用相同的绝对路径列出它-它工作,文件在那里:
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的路径执行它:
LPI@Reboot /cygdrive/c/Users
$ LPI/3DSiteSoftware/Code/Scripts/path_name.pl
USAGE: LPI/3DSiteSoftware/Code/Scripts/path_name.pl -p|-n <string>
LPI@Reboot/cygdrive/c/Users
$LPI/3DSiteSoftware/Code/Scripts/path\u name.pl
用法:LPI/3DSiteSoftware/Code/Scripts/path_name.pl-p |-n
有人知道为什么第一个例子不起作用吗?我被难住了!
谢谢您的建议。我猜您使用的是非Cygwin版本的Perl(如草莓Perl或ActivePerl),它对
/cygdrive/
路径一无所知。您可以通过运行perl-v
来确认这一点。如果它说是为MSWin32构建的,那么它就不是CygwinPerl
所以当你跑步的时候
/cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl
LPI/3DSiteSoftware/Code/Scripts/path_name.pl
狂欢节
perl.exe /cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl
perl.exe LPI/3DSiteSoftware/Code/Scripts/path_name.pl
但是Perl寻找的是
C:/cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl
却找不到
当你跑的时候
/cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl
LPI/3DSiteSoftware/Code/Scripts/path_name.pl
狂欢节
perl.exe /cygdrive/c/Users/LPI/3DSiteSoftware/Code/Scripts/path_name.pl
perl.exe LPI/3DSiteSoftware/Code/Scripts/path_name.pl
Perl将其与当前的C:\Users
目录相结合,并获取
C:\Users\LPI/3DSiteSoftware/Code/Scripts/path_name.pl
(Perl不关心Windows上的混合斜杠)
最简单的解决方案可能只是安装Cygwin版本的Perl,它将理解Cygwin路径。或者您可以编写某种垫片perl
,将脚本名称转换为Windows路径并调用真正的perl.exe
另一种可能是在每个卷上创建/cygdrive
目录(即,创建C:\cygdrive
目录,并使C:\cygdrive\C
成为C:\
的符号链接,C:\cygdrive\d
成为d:
的符号链接,等等)。但是,当您调用Perl脚本时,您必须在任何可能是当前的驱动器上执行此操作。ls-l/cygdrive/c/Users/LPI/3DSiteSoftware/code/Scripts/path_name.pl
返回什么?head-n1 LPI/3DSiteSoftware/code/Scripts/path_name.pl的输出是什么?其他选项:Perl“$(cygpath--dos/cygdrive/../path_name.pl)“
安装cygwin的Perl(如果还不够的话)是不够的。这也是一个调整shebang的问题。是的,我正在使用ActivePerl-我会尝试切换-谢谢!