如何在Windows上使用Perl的默认应用程序打开文件?

时间:2023-01-25 07:37:44

I have a directory of files that I would like to scan on a regular basis and execute with the default application they are associated with. They are not executable so system("file.torrent"); does not work. How are you able to run files with there associated applications in Perl?

我有一个文件目录,我想定期扫描并使用与之关联的默认应用程序执行。它们不是可执行的系统(“file.torrent”);不起作用。你如何在Perl中运行带有相关应用程序的文件?

6 个解决方案

#1


start

You could manually parse the relevant part of the registry, find the associated application, and kick it off yourself: but the command prompt's built-in start command life easier.

您可以手动解析注册表的相关部分,找到关联的应用程序,然后自己启动它:但命令提示符的内置启动命令生活更轻松。

So, for your example you would simply do a system("cmd /c start file.torrent")

因此,对于您的示例,您只需执行一个系统(“cmd / c start file.torrent”)

#2


The standard windows way is with ShellExecute.

标准的Windows方式是使用ShellExecute。

In perl you can do it with, well, ShellExecute. Its in the Win32::GUI package.

在perl中,你可以使用ShellExecute。它在Win32 :: GUI包中。

Have not tried it. But it looks simple enough.

没试过。但它看起来很简单。

#3


Not Perl specific but you can always use the 'start' command. The first argument will be the title of the new command prompt opened and the second argument is the file to open.

不是Perl特定的,但您始终可以使用'start'命令。第一个参数将是打开的新命令提示符的标题,第二个参数是要打开的文件。

system('start "dummy title" "some file.doc"'); # opens the document in word

#4


Another option we use is

我们使用的另一种选择是

system("RunDLL32.exe SHELL32.DLL,ShellExec_RunDLL file.torrent")

system(“RunDLL32.exe SHELL32.DLL,ShellExec_RunDLL file.torrent”)

#5


Never use system() on windows ! Crappy and bad method (PAS)

永远不要在Windows上使用system()!糟糕和糟糕的方法(PAS)

#6


Just to highlight the comment by BeowulfOF above

只是为了突出BeowulfOF上面的评论

system( "test.log" )

will open test.log in it's associated application just the same as entering

将在其关联的应用程序中打开test.log与输入相同

test.log

on the command line

在命令行上

#1


start

You could manually parse the relevant part of the registry, find the associated application, and kick it off yourself: but the command prompt's built-in start command life easier.

您可以手动解析注册表的相关部分,找到关联的应用程序,然后自己启动它:但命令提示符的内置启动命令生活更轻松。

So, for your example you would simply do a system("cmd /c start file.torrent")

因此,对于您的示例,您只需执行一个系统(“cmd / c start file.torrent”)

#2


The standard windows way is with ShellExecute.

标准的Windows方式是使用ShellExecute。

In perl you can do it with, well, ShellExecute. Its in the Win32::GUI package.

在perl中,你可以使用ShellExecute。它在Win32 :: GUI包中。

Have not tried it. But it looks simple enough.

没试过。但它看起来很简单。

#3


Not Perl specific but you can always use the 'start' command. The first argument will be the title of the new command prompt opened and the second argument is the file to open.

不是Perl特定的,但您始终可以使用'start'命令。第一个参数将是打开的新命令提示符的标题,第二个参数是要打开的文件。

system('start "dummy title" "some file.doc"'); # opens the document in word

#4


Another option we use is

我们使用的另一种选择是

system("RunDLL32.exe SHELL32.DLL,ShellExec_RunDLL file.torrent")

system(“RunDLL32.exe SHELL32.DLL,ShellExec_RunDLL file.torrent”)

#5


Never use system() on windows ! Crappy and bad method (PAS)

永远不要在Windows上使用system()!糟糕和糟糕的方法(PAS)

#6


Just to highlight the comment by BeowulfOF above

只是为了突出BeowulfOF上面的评论

system( "test.log" )

will open test.log in it's associated application just the same as entering

将在其关联的应用程序中打开test.log与输入相同

test.log

on the command line

在命令行上