perl - 在不带扩展名的Windows上运行Perl脚本

标签 perl executable

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

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

perl myscript.pl [my_script_parameters]

现在,由于该文件与perl相关联,因此我也可以将其运行为:
myscript.pl [my_script_parameters] 

现在,我知道在某处有一个扩展列表,这些扩展被视为可执行文件(.exe,.bat等)。我想 .pl 添加到此列表中,以便可以像这样运行我的脚本:
myscript [my_script_parameters]

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

最佳答案

是的,对此有内置支持。如果检查命令FTYPE的帮助,将看到一个perl示例。

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 - 在不带扩展名的Windows上运行Perl脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3677114/

相关文章:

c++ - "Launch Failed. Binary Not Found."雪豹和Eclipse C/C++ IDE问题

json - 安装 Perl 模块时 "Fatal error: ' EXTERN.h ' file not found"

regex - 如果使用分组元字符,搜索和替换正则表达式会给出两个不同的输出

linux - Perl 目录查找器不起作用?

.net - 当 Windows 能够找到它时,如何找到 Mercurial 可执行文件的完整路径?

macos - 如何在 32 位或 64 位环境中以编程方式启动程序?

regex - 如何匹配不是某些单词的单词?

perl - 如何在Perl中伪造STDIN?

executable - 将自定义数据嵌入到不会被 ld.so 映射的 ELF 文件中

executable - 有运行时代码修改的聪明案例吗?