Detect forks in capture; document lack of support
David Golden
8 years ago
360 | 360 | # _debug( "# redirecting in parent ...\n" ); |
361 | 361 | _open_std( $stash->{new} ); |
362 | 362 | # execute user provided code |
363 | my ($exit_code, $inner_error, $outer_error, @result); | |
363 | my ($exit_code, $inner_error, $outer_error, $orig_pid, @result); | |
364 | 364 | { |
365 | $orig_pid = $$; | |
365 | 366 | local *STDIN = *CT_ORIG_STDIN if $localize{stdin}; # get original, not proxy STDIN |
366 | 367 | # _debug( "# finalizing layers ...\n" ); |
367 | 368 | _relayer(\*STDOUT, $layers{stdout}) if $do_stdout; |
389 | 390 | # return captured output, but shortcut in void context |
390 | 391 | # unless we have to echo output to tied/scalar handles; |
391 | 392 | my %got; |
392 | if ( defined wantarray or ($do_tee && keys %localize) ) { | |
393 | if ( $orig_pid == $$ and ( defined wantarray or ($do_tee && keys %localize) ) ) { | |
393 | 394 | for ( keys %do ) { |
394 | 395 | _relayer($stash->{capture}{$_}, $layers{$_}); |
395 | 396 | $got{$_} = _slurp($_, $stash); |
676 | 677 | |
677 | 678 | Attempting to modify STDIN, STDOUT or STDERR ~during~ {capture} or {tee} is |
678 | 679 | almost certainly going to cause problems. Don't do that. |
680 | ||
681 | *Forking inside a capture* | |
682 | ||
683 | Forks aren't portable. The behavior of filehandles during a fork is even | |
684 | less so. If Capture::Tiny detects that a fork has occurred within a | |
685 | capture, it will shortcut in the child process and return empty strings for | |
686 | captures. Other problems may occur in the child or parent, as well. | |
687 | Forking in a capture block is not recommended. | |
679 | 688 | |
680 | 689 | == No support for Perl 5.8.0 |
681 | 690 |