Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Launching a data file in Win32 using the assciated application automatically

by tinypig (Beadle)
on May 04, 2003 at 03:59 UTC ( #255420=perlquestion: print w/replies, xml ) Need Help??

tinypig has asked for the wisdom of the Perl Monks concerning the following question:

I have written a module that allows you to Launch('file.txt') or Launch('file.bmp'), etc. from Win32 so that the associated app (retrieved from the registry) automatically opens with the file specified. I have searched on CPAN and Google for a method of doing this in an effort to ensure I am not re-inventing the wheel. The standard method of launching a Windows process doesn't seem to accomplish this on its own.

My specific question is: is there already a way of doing what I have described? My more general question is: are there other ideas for determining if I am writing something that already exists? While searching for this specific functionality, I felt awkward when trying to come up with words to describe the function, or example, depending often on the word "launch".

  • Comment on Launching a data file in Win32 using the assciated application automatically

Replies are listed 'Best First'.
Re: Launching a data file in Win32 using the assciated application automatically
by Limbic~Region (Chancellor) on May 04, 2003 at 04:09 UTC
    tinypig,
    Forgive me, but I work on *nix mostly. I believe the way Win32 does the launching is by having explorer look at the registry. There is a section of the registry devoted to file association. It says what application to launch and with what parameters.

    I did a quick search on CPAN and couldn't find anything that did exactly what you are looking for, but you might want to have a look at:

  • Tie::Registry written by tye
  • Win32::Registry::File

    Basically what you are going to want to do is determine the file extension, look up its association in the registry, and launch the application with the correct parameter to open the file. notepad.exe file for example.

    Cheers - L~R

      Thanks very much for the reply. The module actually uses Tie::Registry and works quite well on 98 and NT (so far). I just wanted to make sure I wasn't offering something that had already been written, and maybe get some tips on searching for functionality in modules.
Re: Launching a data file in Win32 using the assciated application automatically
by guha (Priest) on May 04, 2003 at 13:57 UTC
    No need to dig through the registry ....
    #perl -w my @cmd = qw{start foo.txt}; system(@cmd);
    if you don't want to return to the perlprogram, use exec instead of system.
      That's the ticket. Thanks very much!
Re: Launching a data file in Win32 using the assciated application automatically
by vek (Prior) on May 04, 2003 at 05:01 UTC
    ...are there other ideas for determining if I am writing something that already exists?

    tinypig I think you've pretty much covered the bases. Searching the CPAN and googling for an answer were two good starts. Finally, if in doubt ask here at the Monastery. The only other thing I could suggest would be posting your question on the perl-win32-users mailing list.

    -- vek --
Re: Launching a data file in Win32 using the assciated application automatically
by Jenda (Abbot) on May 04, 2003 at 21:35 UTC

    I've just uploaded a new version (0.14.0) of Win32::FileOp to my page and CPAN that allows you to call the Win32 API function ShellExecute like this:

    use Win32::FileOp qw(:EXECUTE); ShellExecute $filename; ShellExecute 'edit', $filename; ShellExecute 'edit', $filename, {show => SW_SHOWMAXIMIZED}; ShellExecute $exefilename, { params => 'some params', show => SW_SHOWMAXIMIZED }; ...

    Let me know if you have any problems with it :-)

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    P.S.: It will not be on CPAN immediately! You can get if from my page or via PPM from http://jenda.krynicky.cz/perl

    Edit by castaway: Closed small tag in signature

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://255420]
Approved by Enlil
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2023-03-22 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (60 votes). Check out past polls.

    Notices?