This module is specifically for use with Win32::Process::Create. That interface
requires the full path name of an executable, which FetchCommand provides based
on the filename 'extension'.
It is not always obvious (to a program) which executable should be run to
process a given file, so this module provides a registry lookup to get the
associated executable.
@COMMAND = FetchCommand(FILENAME.EXT [, OPTION])
Search the registry (HKEY_CLASSES_ROOT) for the full command to 'open' (run)
the specified file. Commands with embedded environment variables are expanded.
For example:
my @Cmd = FetchCommand('OneHumpOrTwo.pl');
returns an array with (on my machine) 'C:\Perl\bin\perl.exe' in the first
element, and 'OneHumpOrTwo.pl' in the second.
my @Cmd = FetchCommand('test.txt');
returns the items 'C:\WINDOWS\system32\NOTEPAD.EXE' and 'test.txt' in @Cmd.
In its simplest form, just the filename extension need be specified, for
example:
my @Cmd = FetchCommand('.doc');
returns a three item list 'C:\Program Files\Microsoft Office\Office\WINWORD.EXE',
the option '/n', and the extension it applies to, '.doc'.
By default the 'open' option is used, but applications often offer others.
Optionally a different option, like 'print', or 'printto', may be specified as
a second argument. For example, the following will use the default .txt print
command (typically NOTEPAD.EXE) to print the file 'classes.txt':
Consult your application documentation (or peek in the registry) to find which
options are supported.
Some commands have insertion strings, like %1, %l, %L, and %*. Only limited
substitution is done, where %1, %l, and %L have FILENAME.EXT substituted and
%* is ignored. This covers most cases. If the insertion string is embedded
in another then no substitution is performed. Other substitution strings are
copied to the output list.
Commands without insertion strings have FILENAME.EXT pushed into the last
element. For example:
The resulting list can be used in a call to Win32::Process::Create, with the
first element as the second argument, and the rest of the list as the third.
For example:
use Win32::Process;
use Win32::FetchCommand;
my $Obj;
my ($Exe, @CmdLine) = FetchCommand('c:\\cv.doc');