在没有扩展名的Windows上运行perl脚本

Pas*_*cal 9 perl executable

我试图找到一种方法来注册扩展.pl名为可执行文件的文件.我花了一些时间在网上寻找解决方案,但我找不到任何东西.

我能做什么:我制作了一个脚本,让我们称它为myscript.pl
我可以像这样运行它:

perl myscript.pl [my_script_parameters]
Run Code Online (Sandbox Code Playgroud)

既然文件与perl相关联,我也可以将其运行为:

myscript.pl [my_script_parameters] 
Run Code Online (Sandbox Code Playgroud)

现在,我知道有一些扩展名列表被认为是可执行文件(.exe,.bat等等).我想添加 .pl 到此列表,以便我可以像这样运行我的脚本:

myscript [my_script_parameters]
Run Code Online (Sandbox Code Playgroud)

有谁知道如何做到这一点?

Ed *_*ess 13

是的,内置支持.如果您查看命令FTYPE的帮助,您将看到一个perl示例.

C:>帮助ftype

显示或修改文件扩展名关联中使用的文件类型

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 %*
Run Code Online (Sandbox Code Playgroud)

would allow you to invoke a Perl script as follows:

script.pl 1 2 3
Run Code Online (Sandbox Code Playgroud)

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

set PATHEXT=.pl;%PATHEXT%
Run Code Online (Sandbox Code Playgroud)

and the script could be invoked as follows:

script 1 2 3
Run Code Online (Sandbox Code Playgroud)


And*_*Dog 6

您只需将"; .PL"添加到PATHEXT环境变量即可.右键单击"我的电脑">"属性">"高级">"环境变量">"系统变量".