如何创建拖放草莓Perl程序?

时间:2022-08-22 20:26:17

I've got a Strawberry Perl program that accepts a single-file as a command-line argument. How can I set things up such that I can drag and drop the desired file onto the Strawberry Perl program (or a wrapper around it) and the program runs with that file's name as an argument?

我有一个Strawberry Perl程序,它接受单个文件作为命令行参数。我如何设置,以便我可以将所需的文件拖放到Strawberry Perl程序(或它周围的包装器)上,程序以该文件的名称作为参数运行?

3 个解决方案

#1


20  

Under Windows (tested with XP), you can create a .cmd file and simply have it run the Perl program with the argument of %1 to pass the filename over, as if executed by commandline.

在Windows下(使用XP测试),您可以创建一个.cmd文件,只需让它运行带有%1参数的Perl程序来传递文件名,就像在命令行执行一样。

perl c:\test.pl %1

Then you can simply drag and drop a file onto the .cmd file to execute.

然后,您只需将文件拖放到.cmd文件即可执行。

#2


18  

Eeek! Please don't create a wrapper script/cmd when you don't need to.

Eeek!如果不需要,请不要创建包装器脚本/ cmd。

Go into your Registry or your File Type dialog box in Windows, and redefine the Perl default action to say:

进入您的注册表或Windows中的文件类型对话框,并重新定义Perl默认操作,说:

"C:\path-to-perl-folders\perl.exe" "%1" %*

This will cause double-clicking the .PL to launch perl.exe with the name of the double-clicked file (%1). The %* stuff (passing any filename arguments to the Perl script) is trickier.

这将导致双击.PL以使用双击文件(%1)的名称启动perl.exe。 %* stuff(将任何文件名参数传递给Perl脚本)比较棘手。

Go into the Registry again (really, it's not as scary as people think) and find/create a "shellex" key under the Perl class, and then create a sub-key called "DropHandler" with a default string value of "{86C86720-42A0-1069-A2E8-08002B30309D}" (at least, that's my DropHandler in the US version of Windows XP).

再次进入注册表(实际上,它并不像人们想象的那么可怕)并在Perl类下找到/创建一个“shellex”键,然后创建一个名为“DropHandler”的子键,其默认字符串值为“{86C86720” -42A0-1069-A2E8-08002B30309D}“(至少,这是我在美国版Windows XP中的DropHandler)。

This allows .pl files (actually, anything associated with the Perl class) to have a drop handler that tells Explorer what to do when you drop file(s) on the .pl script. In this case, it just means "run the Perl script with the dropped file(s) as arguments".

这允许.pl文件(实际上,与Perl类相关联的任何内容)具有一个drop处理程序,告诉Explorer在.pl脚本上删除文件时该怎么做。在这种情况下,它只是意味着“以删除的文件作为参数运行Perl脚本”。

Hmmm, I don't think I explained that very well, but that's how I've set up Perl (running off a network drive) for a large engineering organization. Google for Perl and DropHandler, and you should be able to get the .reg Registry script to do this for you.

嗯,我不认为我解释得那么好,但这就是我为一个大型工程组织设置Perl(运行网络驱动器)的方式。 Google for Perl和DropHandler,您应该能够获得.reg注册表脚本来为您执行此操作。

#3


1  

Here's another alternative to a "wrapper", but it requires a slight modification to the perl script:

这是“包装器”的另一种替代方法,但它需要对perl脚本稍作修改:

  1. Rename your script.pl script to script.cmd.
  2. 将script.pl脚本重命名为script.cmd。
  3. Add the following to the top of the file:
  4. 将以下内容添加到文件顶部:

@SETLOCAL ENABLEEXTENSIONS
@c:\path\to\perl.exe -x "%~f0" %*
@exit /b %ERRORLEVEL%
#!perl
#line 6
# ...perl script continues here...

@SETLOCAL ENABLEEXTENSIONS @c:\ path \ to \ perl.exe -x“%~f0”%* @exit / b%ERRORLEVEL%#!perl #line 6#... perl脚本在这里继续...

The script is run like any other batch file. The first three lines basically invokes Perl on the CMD file itself (%~f0, which only works if CMD extensions are turned on). The -x paremeter to perl.exe tells Perl to skip everything until the #!perl line. "#line 6" just aids in debugging.

该脚本与任何其他批处理文件一样运行。前三行基本上在CMD文件本身上调用Perl(%~f0,仅在CMD扩展打开时才有效)。 perl.exe的-x paremeter告诉Perl跳过#!perl行之前的所有内容。 “#line 6”只是帮助调试。

This is my preferred solution when I don't know much about the target system (and may not be able to edit the registry).

当我对目标系统了解不多(并且可能无法编辑注册表)时,这是我首选的解决方案。

#1


20  

Under Windows (tested with XP), you can create a .cmd file and simply have it run the Perl program with the argument of %1 to pass the filename over, as if executed by commandline.

在Windows下(使用XP测试),您可以创建一个.cmd文件,只需让它运行带有%1参数的Perl程序来传递文件名,就像在命令行执行一样。

perl c:\test.pl %1

Then you can simply drag and drop a file onto the .cmd file to execute.

然后,您只需将文件拖放到.cmd文件即可执行。

#2


18  

Eeek! Please don't create a wrapper script/cmd when you don't need to.

Eeek!如果不需要,请不要创建包装器脚本/ cmd。

Go into your Registry or your File Type dialog box in Windows, and redefine the Perl default action to say:

进入您的注册表或Windows中的文件类型对话框,并重新定义Perl默认操作,说:

"C:\path-to-perl-folders\perl.exe" "%1" %*

This will cause double-clicking the .PL to launch perl.exe with the name of the double-clicked file (%1). The %* stuff (passing any filename arguments to the Perl script) is trickier.

这将导致双击.PL以使用双击文件(%1)的名称启动perl.exe。 %* stuff(将任何文件名参数传递给Perl脚本)比较棘手。

Go into the Registry again (really, it's not as scary as people think) and find/create a "shellex" key under the Perl class, and then create a sub-key called "DropHandler" with a default string value of "{86C86720-42A0-1069-A2E8-08002B30309D}" (at least, that's my DropHandler in the US version of Windows XP).

再次进入注册表(实际上,它并不像人们想象的那么可怕)并在Perl类下找到/创建一个“shellex”键,然后创建一个名为“DropHandler”的子键,其默认字符串值为“{86C86720” -42A0-1069-A2E8-08002B30309D}“(至少,这是我在美国版Windows XP中的DropHandler)。

This allows .pl files (actually, anything associated with the Perl class) to have a drop handler that tells Explorer what to do when you drop file(s) on the .pl script. In this case, it just means "run the Perl script with the dropped file(s) as arguments".

这允许.pl文件(实际上,与Perl类相关联的任何内容)具有一个drop处理程序,告诉Explorer在.pl脚本上删除文件时该怎么做。在这种情况下,它只是意味着“以删除的文件作为参数运行Perl脚本”。

Hmmm, I don't think I explained that very well, but that's how I've set up Perl (running off a network drive) for a large engineering organization. Google for Perl and DropHandler, and you should be able to get the .reg Registry script to do this for you.

嗯,我不认为我解释得那么好,但这就是我为一个大型工程组织设置Perl(运行网络驱动器)的方式。 Google for Perl和DropHandler,您应该能够获得.reg注册表脚本来为您执行此操作。

#3


1  

Here's another alternative to a "wrapper", but it requires a slight modification to the perl script:

这是“包装器”的另一种替代方法,但它需要对perl脚本稍作修改:

  1. Rename your script.pl script to script.cmd.
  2. 将script.pl脚本重命名为script.cmd。
  3. Add the following to the top of the file:
  4. 将以下内容添加到文件顶部:

@SETLOCAL ENABLEEXTENSIONS
@c:\path\to\perl.exe -x "%~f0" %*
@exit /b %ERRORLEVEL%
#!perl
#line 6
# ...perl script continues here...

@SETLOCAL ENABLEEXTENSIONS @c:\ path \ to \ perl.exe -x“%~f0”%* @exit / b%ERRORLEVEL%#!perl #line 6#... perl脚本在这里继续...

The script is run like any other batch file. The first three lines basically invokes Perl on the CMD file itself (%~f0, which only works if CMD extensions are turned on). The -x paremeter to perl.exe tells Perl to skip everything until the #!perl line. "#line 6" just aids in debugging.

该脚本与任何其他批处理文件一样运行。前三行基本上在CMD文件本身上调用Perl(%~f0,仅在CMD扩展打开时才有效)。 perl.exe的-x paremeter告诉Perl跳过#!perl行之前的所有内容。 “#line 6”只是帮助调试。

This is my preferred solution when I don't know much about the target system (and may not be able to edit the registry).

当我对目标系统了解不多(并且可能无法编辑注册表)时,这是我首选的解决方案。