在不带扩展名的Windows上运行Perl脚本 [英] Running a perl script on windows without extension

查看:70
本文介绍了在不带扩展名的Windows上运行Perl脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to find a way to register the files with extension .pl as executables. I spent some time on the web looking for a solution, but I couldn't find anything.

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

What I can do: I made a script, let's call it myscript.pl
I can run it like this :

perl myscript.pl [my_script_parameters]

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

Now since the file is associated with perl, I can also run it as:

myscript.pl [my_script_parameters] 

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

Now, I know that there is somewhere a list of extensions that are considered as executables (.exe, .bat, etc…). I would like to add .pl to this list so that I can run my script like this:

myscript [my_script_parameters]

有人知道该怎么做吗?

推荐答案

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

Yes, there is built-in support for this. If you check the help for command FTYPE you will see a perl example.

C:>帮助ftype

C:>help ftype

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

Displays or modifies file types used in file extension associations

FTYPE [fileType [= [openCommandString]]]

FTYPE [fileType[=[openCommandString]]]

fileType指定要使用的文件类型 检查或更改openCommandString 指定在以下情况下使用的打开命令 启动文件 这种类型的.

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

没有参数的FTYPE类型 显示当前的文件类型 定义了打开的命令字符串. 仅用一个文件调用FTYPE 类型,它显示当前打开的 该文件类型的命令字符串. 不为open命令指定任何内容 字符串,FTYPE命令将 删除打开命令字符串 文件类型.在打开命令内 字符串%0或%1被替换为 通过启动的文件名 联想. %*得到所有 参数和%2获得第一 参数,%3秒,依此类推.%〜n 获取所有剩余的参数 从第n个参数开始,其中 n可以在2到9之间(含2和9). 例如:

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 %*

将允许您调用Perl 脚本如下:

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

这篇关于在不带扩展名的Windows上运行Perl脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆