Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.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
Windows GetOpt不工作_Windows_Perl - Fatal编程技术网

Windows GetOpt不工作

Windows GetOpt不工作,windows,perl,Windows,Perl,因此,最近在一台新计算机上安装了activeperl5.10.0(ActivePerl-5.10.0.1003-MSWin32-x86-285500),以运行我在旧计算机上运行的代码(使用相同的版本和代码)。这段代码在旧电脑上运行良好,但在新电脑上却不行 虽然它在cmd.exe中启动时将运行.pl文件,但它会忽略我添加到其中的任何命令行参数。这让我觉得我遗漏了一些东西,因此Getopt::Long被识别了。有什么想法吗 例如,当我在代码中输入类似的内容时 Getopt::Long; GetOpt

因此,最近在一台新计算机上安装了activeperl5.10.0(ActivePerl-5.10.0.1003-MSWin32-x86-285500),以运行我在旧计算机上运行的代码(使用相同的版本和代码)。这段代码在旧电脑上运行良好,但在新电脑上却不行

虽然它在cmd.exe中启动时将运行.pl文件,但它会忽略我添加到其中的任何命令行参数。这让我觉得我遗漏了一些东西,因此Getopt::Long被识别了。有什么想法吗

例如,当我在代码中输入类似的内容时

Getopt::Long;
GetOptions(\%args, "b")
如果“b”是用于在脚本中设置某些代码的参数,则它将不接受

script.pl -b
但它会接受的

script.pl
此外,如果我将“perl”放在参数前面,参数也会起作用,如下所示:

perl script.pl -b

感谢您愿意提供的任何帮助

这不是perl的问题;这是一个Windows配置问题。具体而言,.PL文件类型关联配置不正确

您可以使用ftype命令修复它

C:>帮助ftype

Displays or modifies file types used in file extension associations

FTYPE [fileType[=[openCommandString]]]

  fileType  Specifies the file type to examine or change
  openCommandString Specifies the open command to use when launching files
                    of this type.

Type FTYPE without parameters to display the current file types that
have open command strings defined.  FTYPE is invoked with just a file
type, it displays the current open command string for that file type.
Specify nothing for the open command string and the FTYPE command will
delete the open command string for the file type.  Within an open
command string %0 or %1 are substituted with the file name being
launched through the assocation.  %* gets all the parameters and %2
gets the 1st parameter, %3 the second, etc.  %~n gets all the remaining
parameters starting with the nth parameter, where n may be between 2 and 9,
inclusive.  For example:

    ASSOC .pl=PerlScript
    FTYPE PerlScript=perl.exe %1 %*

would allow you to invoke a Perl script as follows:

    script.pl 1 2 3

If you want to eliminate the need to type the extensions, then do the
following:

    set PATHEXT=.pl;%PATHEXT%

and the script could be invoked as follows:

    script 1 2 3

除非我们能看到您试图执行的代码,否则任何答案都是猜测。打印/显示错误您是如何安装草莓Perl的?您是如何运行Perl文件的?OP运行的是ActiveState Perl,而不是草莓Perl。很抱歉解释得不好。第一次在网站上发布代码帮助。但是OP说Perl文件正在运行是的,脚本在运行,但是OP也说它不接受/看到参数。这是因为文件类型关联缺少config.Ah的
%1%*
部分,所以他们将文件作为
script.pl
运行,而不是
perl script.pl
好的,所以
perl script.pl
带参数运行。如果我理解正确,
ASSOC.pl=PerlScript
FTYPE PerlScript=perl.exe%1%*
应该是解决此问题所需的全部。但是,通过尝试,它没有改变任何事情。我错过什么了吗?试着打开一个新的cmd窗口。在进行这些类型的更改时,Windows有时不会更新当前cmd shell的环境。