in reply to Perl open pipe exiting early

use sub Fudge

Also, get rid of $sub_failed

if( my $pid = open ... ){ } else { die Fudge(); }

Or use https://metacpan.org/pod/Capture::Tiny#capture_merged

Replies are listed 'Best First'.
Re^2: Perl open pipe exiting early
by albob (Sexton) on Apr 03, 2015 at 11:34 UTC
    Hi,

    Thanks for the response. Will the use of fudge only work though if I know the failure point? My script "fails" when the the script thinks that my file handle's reference count has reached zero before it should have done. I am not sure how I can catch this issue using fudge. Or should i just run the fudge procedure every time and it will eventually catch the information I need?

    if (my $pid = open(...) { while(<FH>) { } fudge(): } else{ }

    Thanks

    (The issue is made difficult by the fact that I can't reproduce the issue locally....but multiple users are seeing it. Makes debugging difficult!)

      Thanks for the response. Will the use of fudge only work though if I know the failure point?

      Use it in every place there can be a failure ... open or Fudge() ... close or Fudge() ... even readline or Fudge();

      while ( ! eof($fh) ) { defined( $_ = <$fh> ) or die Fudge("readline \$fh"); ... }

      Heck, even enhance it to sparkle some $? extras

      sub Fudge { my $pipe = $?; use Errno(); my $msg = join qq/\n/, "Error @_", map { " $_" } int( $! ) . q/ / . $!, int( $^E ) . q/ / . $^E, grep( { $!{$_} } keys %! ) ; $^E = $! = $pipe; $msg .= join qq/\n/, map { " $_" } "\n #", #~ int( $! ) . q/ / . $!, #~ int( $^E ) . q/ / . $^E, 'status($?) '.( $pipe ), 'subexit($? >>8) '.( $pipe >> 8), 'signal($? & 127) '.( $pipe & 127 ), 'coredump($? & 128) '.( $pipe & 128 ), grep( { $!{$_} } keys %! ), q/ /; return $msg; }