Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从另一个具有.pl扩展名的perl脚本执行一个没有.pl扩展名的perl脚本_Perl - Fatal编程技术网

从另一个具有.pl扩展名的perl脚本执行一个没有.pl扩展名的perl脚本

从另一个具有.pl扩展名的perl脚本执行一个没有.pl扩展名的perl脚本,perl,Perl,如何在Windows上使用另一个名为second.pl的perl脚本中名为“first”(无扩展名)的文件执行perl脚本 第一个文件的文件内容: #!/usr/bin/perl5.8.4 -w >> Some code second.pl的文件内容: #!/usr/bin/perl use strict; use warnings; system "first"; 因此,我的问题是,当我从Windows命令行执行文件“first”时,它会工作 但是如果我尝试从我的文件“sec

如何在Windows上使用另一个名为second.pl的perl脚本中名为“first”(无扩展名)的文件执行perl脚本

第一个文件的文件内容:

#!/usr/bin/perl5.8.4 -w
>> Some code
second.pl的文件内容:

#!/usr/bin/perl
use strict;
use warnings;

system "first";
因此,我的问题是,当我从Windows命令行执行文件“first”时,它会工作

但是如果我尝试从我的文件“second.pl”运行它,使用
system“first”
它失败,出现以下错误:

can't exec "first" : Not a directory at "second.pl" at line 6

Windows使用文件扩展名计算如何运行文件。由于您没有扩展,操作系统会认为您正在尝试打开一个目录

您可以通过更改
系统“first”来解决此问题

system $^X, "first"

这将使Windows再次运行当前的Perl解释器,将您的脚本名作为第一个参数传递,这将使Perl运行它。

那么
system'open first'
呢?或者
system'/path/to/Perl/path/to/first'
防御性编程建议:很容易安装几个Perl,有时在不知情的情况下,
system“perl”
可能无法运行您期望的程序。使用(与当前运行的Perl相同)或硬编码完整路径。