in reply to Re: Re: Problems with open
in thread Problems with open

grep {-x "$_/$program"} split /:/ => $ENV {PATH};
And if $program starts with a slash, you can just check -x $program.

The other problem is more general. If the program exists, the fork and the exec will work. The other program *will* get started. The only "problem" is that it will terminate sooner than you expect. Hence, your pipe will be "broken". In that case (printing to a pipe that was closed on the other hand), your program will get a SIGPIPE. You could write something like:

eval { local $SIG {PIPE} = sub {die "Pipe!"}; print FH "Whatever\n"; .... close FH or die; }; if ($@ && $@ =~ /^Pipe!/) { ... Do something ... }
Note that you might reach the end of the eval before the SIGPIPE is delivered though.

Abigail

Replies are listed 'Best First'.
Re: Re: Problems with open
by skerr1 (Sexton) on Jul 24, 2002 at 16:35 UTC
    Good solutions and good help. Thanks very much!

    -Shannon