in reply to Re: J.A.P.H. with intentional eval failure
in thread J.A.P.H. with intentional eval failure

If by 'misdirection' you mean "Gee it sure looks like you posted the wrong code..." then you are right on the money. I've updated it with one that does fail, as advertized, the first time through. It should be noted that this program does not actually eval the string on the first line without modifying it heavily. In the case of the old code something like 'print "J.A.P.H \n";%70^72#...' was being eval-ed. As you mention, that line is runnable.

Anyways, I've been trying to figure out how to block error messages and STDOUT generated in functions used in my programs that were written by other people. 'close' seems to work great! Thanks! Do you know how to re-open STDERR and STOUT properly?

  • Comment on Re^2: J.A.P.H. with intentional eval failure

Replies are listed 'Best First'.
Re^3: J.A.P.H. with intentional eval failure
by jdalbec (Deacon) on Mar 01, 2005 at 00:48 UTC
    perldoc -f open has examples. Basically you duplicate STDOUT and STDERR to other filehandles before closing them. Then you duplicate the saved filehandles back to STDOUT and STDERR.
    print "STDOUT #1\n";warn "STDERR #1\n"; open my $savestdout, '>&', \*STDOUT; print "STDOUT #2\n";warn "STDERR #2\n"; open my $savestderr, '>&', \*STDERR; print "STDOUT #3\n";warn "STDERR #3\n"; close STDOUT; print "STDOUT #4\n";warn "STDERR #4\n"; close STDERR; print "STDOUT #5\n";warn "STDERR #5\n"; open STDOUT, '>&', $savestdout; print "STDOUT #6\n";warn "STDERR #6\n"; open STDERR, '>&', $savestderr; print "STDOUT #7\n";warn "STDERR #7\n"; close $savestdout; print "STDOUT #8\n";warn "STDERR #8\n"; close $savestderr; print "STDOUT #9\n";warn "STDERR #9\n";
    OK, this is bizarre. When I re-open STDOUT, I get output from warn even though STDERR is still closed. perldoc -f warn doesn't describe this behavior.

      Thank you for the guidance. There is lots of good stuff in perldocs. Just shows how much of a noob I am to perl that I didn't go straight to perldoc, instead of searching aimlessly online (darn google!).

      I had to change the code you provided slightly to get it to run on my version of perl. (Adding parenthisis, moving quote locations, nothing major) I'm running perl v5.6.0 built for MSWin32-x86-multi-thread, but don't quote me on that. Anyways, here is the results I get.

      STDOUT #1 STDERR #1 STDOUT #2 STDERR #2 STDOUT #3 STDERR #3 STDERR #4 STDOUT #6 STDERR #6 STDOUT #7 STDERR #7 STDOUT #8 STDERR #8 STDOUT #9 STDERR #9

      Like you said, the line 'STDERR #6' shouldn't be printing....hmmm...