in reply to Viewing a PDF file from a Perl program

you don't give an OS, under Linux, both of these work.

system "acroread poe.pdf &"; # or (needs error checking) if (fork) { print "bye$/" } else { system acroread => "poe.pdf" }

Replies are listed 'Best First'.
Re: Re: Viewing a PDF file from a Perl program
by bronto (Priest) on Mar 24, 2003 at 09:24 UTC

    ++zengargoyle

    IMHO the best (i.e.: more portable) way to do it is fork, since it works on every UNIX-like OS and it is emulated on Win32, and it won't "freeze" your application. Calling system "acroread poe.pdf &"; won't work on non-UNIX systems

    Ciao!
    --bronto


    The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
    --John M. Dlugosz
      ... but it is buggy for at least 5.6.0 and not ported to everywhere. Also will not work in any way with perl-5.005 on Win32.

      So it is no way more portable.

      Courage, the Cowardly Dog

        Right. So, if perlgrl needed a reason to upgrade his/her Perl to 5.8, you gave him/her two ;-)

        Ciao!
        --bronto


        The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
        --John M. Dlugosz

      indeed fork is the only way to go.

      other replys have suggested:

      system start => acrord32 => $pdf_file; # or system start => $pdf_file;
      neither of which has any hope of running anywhere but Windows.

      for cross-platform-ability have a config setting for the reader executable.

      # in child after fork (close STD* for good measure) close STDIN; close STDOUT; close STDERR; system $cfg{PDFViewer}, $pdf_file;

      i'm sure there are modules on CPAN that abstract Running a program for multiple OSs.

Re: Re: Viewing a PDF file from a Perl program
by ehdonhon (Curate) on Mar 25, 2003 at 02:44 UTC

    Also, if you want to make sure that acroread doesn't send anything to STDOUT that might mess up your screen, take a look at Proc::Daemon::Init.

      nope, Proc::Daemon::Init doesn't return to the parent after it is called, so you would still have to fork around it. it does have some nice code for fork-ing and close-ing all open handles so it's good to look at.

Forked Children Should Exit
by belden (Friar) on Mar 25, 2003 at 21:13 UTC
    Urmm... what's to stop your child from falling through to the parent code? Usually forked kids have an exit() to prevent this from happening. If you used exec() instead of system(), then you'd have an implicit exit. I think you need an exit. If not, I'm curious why.

    blyman
    setenv EXINIT 'set noai ts=2'