Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: How to 'invoke' a PDF file on Win32

by svad (Pilgrim)
on Apr 23, 2002 at 16:50 UTC ( [id://161370]=note: print w/replies, xml ) Need Help??


in reply to Re: How to 'invoke' a PDF file on Win32
in thread How to 'invoke' a PDF file on Win32

I tried namely
perldoc Win32::Process
! The main problem is I can not 'invoke' pdf files directly using it.

OTOH I've almost solved this by determining of associated to '.pdf' command line and invoking that file. So, following works (with console window appearing for half of a second and then disappearing):

use Win32::Process; sub ErrorReport{ print Win32::FormatMessage(Win32::GetLastError()); } my ($ftype) = `assoc .pdf`=~/=(.*)/; print $ftype,"\n"; my ($apath) = `ftype $ftype`=~/=(.*)/; print $apath,"\n"; my $procobj; $apath=~s/"%1"$//; $apath=~s/^"//; $apath=~s/"\s*$//; Win32::Process::Create( $procobj, "$apath", "x D:\\WORK\\Documentation\\cd-writing\\perl-technology\\root-cd-tk\ +\files\\PSAX1250_IG_R610_Iss1-mp.pdf", 0, NORMAL_PRIORITY_CLASS, "." ) || die ErrorReport();
This works good. May be it is needed to search in registry instead of `assoc` and `ftype`. When I'll come with a final solution I'll probably report this in 'code' section.

Replies are listed 'Best First'.
Re: Re: Re: How to 'invoke' a PDF file on Win32
by jsprat (Curate) on Apr 23, 2002 at 16:59 UTC
    Here's a better solution, using the ShellExecute API. This works as-is:

    #!/usr/bin/perl -w use strict; #use diagnostics; use warnings; use Win32::API; my $ShellExecute = new Win32::API("shell32", "ShellExecute", [qw(N P P + P P N)], 'N'); my $hWnd; $ShellExecute->Call($hWnd, 'open', 'c:/rc.d.pdf', undef, undef, 1);

    Try perldoc Win32::API, then find a good API reference. A lot of VB oriented sites will have good info.
      YES!

      Thank you!

      That is exactly what I've searched for... Now I will test it on different Win32 platforms and will use this.

      Warmest wishes,
      Vadim.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2025-03-17 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (56 votes). Check out past polls.