Skip to main content.
home | support | download

Back to List Archive

Re: Which PDF file?

From: Bill Moseley <moseley(at)>
Date: Wed Jan 05 2005 - 18:25:41 GMT
On Wed, Jan 05, 2005 at 10:01:54AM -0800, Richard Morin wrote:
> Thanks for the suggestion, but I'm having trouble
> finding anything like the code you describe.

Oh, I'm sorry.  I was working off the current version.

> ~rdm/local/lib/swish-e/perl/SWISH/, I see
>   sub run_program {
>     my $self = shift;
>     die "No arguments passed to run_program()\n"
>         unless @_;
>     die "Must pass arguments to program '$_[0]'\n"
>         unless @_ > 1;
>     my $fh = $^O =~ /Win32/i || $^O =~ /VMS/i
>          ? $self->windows_fork( @_ )
>          : $self->real_fork( @_ );
>     local $/ = undef;
>     return <$fh>;
>   }

The file handle "$fh" is a "my" variable, so it's local to that block
(to the run_program() function).  When that $fh variable goes out of
scope -- falls off the ending brace) it does an automatic close on the
input which implicitly does a watipid() call on the child process.
That waitpid() reaps the child process to prevent zombies.  (The
sub-process waits to fully disappear until the calling program asks for
the child process' exit code.)

But under windows waitpid is not automatically called.  The result was
on Windows a bunch of zombie processes left behind.  On windows
there's not that many slots for processes and the program would hang.

So, getting back to your question, you need to rewrite the code a bit:

    local $/ = undef;
    my $output = <$fh>;
    close $fh || warn "@_ didn't run correctly";

    # When using IPC::Open3 need to reap the processes.
    waitpid $self->{pid}, 0 if delete $self->{pid};

    return $output;

Does that help?

Bill Moseley
Received on Wed Jan 5 10:26:06 2005