Re: Opening a file with its Windows app in Activestate

Discussion in 'Perl Misc' started by Jürgen Exner, Oct 3, 2013.

  1. Bernie Cosell <> wrote:
    >I've got Activestate Perl on my win7/pro system. I've poked through the
    >win32 man pages and I just can't quite figure it out: I'm guessing there
    >must be some easy way for my perl program to tell windows "open <FILE.PDF>"
    >and have the PDF app open the file [and presumably some way I can wait
    >until it exits], or to explicitly say what program, like "OPEN <FILE> with
    ><EXCEL>" Any pointers to what to look at in the docs would be appreciated.


    I suppose you could dig through some Windows API somewhere to find out
    which program is configured to open which file type. But why not let
    Windows do the heavy lifting? A simple
    system ('file.pdf');
    will do the job nicely.

    Please note that very often Windows programs will run in a forked
    process, i.e. system() will return immediately and the application
    program will run independantly in a separate process.

    jue
    Jürgen Exner, Oct 3, 2013
    #1
    1. Advertising

  2. Ben Morrow <> wrote:
    >Quoth J?Exner <>:
    >> Windows do the heavy lifting? A simple
    >> system ('file.pdf');
    >> will do the job nicely.

    >
    >Are you sure?


    Yes. I tried it before I posted the reply.
    Of course *.PDF has to be associated with the proper program.

    >I would be surprised. IIRC from the command-line you have
    >to run
    > start file.pdf


    Correct. Maybe some system() magic on Windows?

    >and it won't wait. (In general it can't wait, because the file might be
    >passed to an already-running instance of the appropriate program.)


    Agreed again.

    >> Please note that very often Windows programs will run in a forked
    >> process,

    >
    >Forked? :)
    >
    >> i.e. system() will return immediately and the application
    >> program will run independantly in a separate process.

    >
    >This is almost never the case if you invoke an application directly;


    Just try a simple
    notepad
    from a DOS command prompt, without a preceeding 'start'.

    >however, if you invoke it through 'start' then I believe start.exe will
    >just contact a running Explorer process to perform the file open, and
    >will exit as soon as it's done that.


    Maybe that's the mechanics behind the scene. And yes, when called with
    'start', then this adds an additional layer and even the few programs
    that normally would cause system() to wait will now run in parallel.
    The important point from a Perl programmers point of view is that for
    many Windows program system() will not wait for them to finish, even
    when not using 'start' but calling the exe directly.

    Been there, done that. At the end for this particularly nasty program
    the only somewhat reliable way to determine if it was still running was
    to check the process table in regular intervals.

    jue
    Jürgen Exner, Oct 3, 2013
    #2
    1. Advertising

  3. On 10/2/2013 6:12 PM, Ben Morrow wrote:
    >
    > Quoth J�rgen Exner <>:
    >> Bernie Cosell <> wrote:
    >> ...

    >
    >> I suppose you could dig through some Windows API somewhere to find out
    >> which program is configured to open which file type. But why not let
    >> Windows do the heavy lifting? A simple
    >> system ('file.pdf');
    >> will do the job nicely.

    >
    > Are you sure? I would be surprised. IIRC from the command-line you have
    > to run
    >
    > start file.pdf
    >
    > and it won't wait. (In general it can't wait, because the file might be
    > passed to an already-running instance of the appropriate program.)
    >


    Running this twice: perl -e "0==system('foo.pdf') or die $?"

    The first waits and the second doesn't. However, in both cases, the
    wait call will return 256 even exiting Adobe normally.

    Peek behind those dark doors at your own peril...

    --
    Charles DeRykus
    Charles DeRykus, Oct 3, 2013
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. thunk
    Replies:
    1
    Views:
    292
    thunk
    Mar 30, 2010
  2. thunk
    Replies:
    0
    Views:
    458
    thunk
    Apr 1, 2010
  3. thunk
    Replies:
    14
    Views:
    603
    thunk
    Apr 3, 2010
  4. Replies:
    6
    Views:
    125
    Joe Smith
    Jan 16, 2005
  5. Guest
    Replies:
    3
    Views:
    339
    C.DeRykus
    Jul 10, 2010
Loading...

Share This Page