Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Re: Opening a file with its Windows app in Activestate

Reply
Thread Tools

Re: Opening a file with its Windows app in Activestate

 
 
Jürgen Exner
Guest
Posts: n/a
 
      10-03-2013
Bernie Cosell <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      10-03-2013
Ben Morrow <(E-Mail Removed)> wrote:
>Quoth J?Exner <(E-Mail Removed)>:
>> 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

 
Reply With Quote
 
 
 
 
Charles DeRykus
Guest
Posts: n/a
 
      10-03-2013
On 10/2/2013 6:12 PM, Ben Morrow wrote:
>
> Quoth J�rgen Exner <(E-Mail Removed)>:
>> Bernie Cosell <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with printing a bit pattern with printf and %x matt.jaffe@gmail.com C Programming 9 04-19-2013 12:14 PM
How to up file with SFTP protocol using Windows Activestate perl? Perl Misc 3 07-10-2010 04:29 AM
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 14 04-03-2010 10:08 AM
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 0 04-01-2010 10:25 PM
Its a bird, its a plane, no ummm, its a Ruide thunk Ruby 1 03-30-2010 11:10 AM



Advertisments