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
|