Codebase list libcapture-tiny-perl / 440556a
Detect forks in capture; document lack of support David Golden 8 years ago
1 changed file(s) with 11 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
360360 # _debug( "# redirecting in parent ...\n" );
361361 _open_std( $stash->{new} );
362362 # execute user provided code
363 my ($exit_code, $inner_error, $outer_error, @result);
363 my ($exit_code, $inner_error, $outer_error, $orig_pid, @result);
364364 {
365 $orig_pid = $$;
365366 local *STDIN = *CT_ORIG_STDIN if $localize{stdin}; # get original, not proxy STDIN
366367 # _debug( "# finalizing layers ...\n" );
367368 _relayer(\*STDOUT, $layers{stdout}) if $do_stdout;
389390 # return captured output, but shortcut in void context
390391 # unless we have to echo output to tied/scalar handles;
391392 my %got;
392 if ( defined wantarray or ($do_tee && keys %localize) ) {
393 if ( $orig_pid == $$ and ( defined wantarray or ($do_tee && keys %localize) ) ) {
393394 for ( keys %do ) {
394395 _relayer($stash->{capture}{$_}, $layers{$_});
395396 $got{$_} = _slurp($_, $stash);
676677
677678 Attempting to modify STDIN, STDOUT or STDERR ~during~ {capture} or {tee} is
678679 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.
679688
680689 == No support for Perl 5.8.0
681690