370 | 370 |
_unproxy( %proxy_std );
|
371 | 371 |
# _debug( "# killing tee subprocesses ...\n" ) if $do_tee;
|
372 | 372 |
_kill_tees( $stash ) if $do_tee;
|
373 | |
# return captured output
|
|
373 |
# return captured output, but shortcut in void context
|
|
374 |
# unless we have to echo output to tied/scalar handles;
|
374 | 375 |
my %got;
|
375 | |
for ( keys %do ) {
|
376 | |
_relayer($stash->{capture}{$_}, $layers{$_});
|
377 | |
$got{$_} = _slurp($_, $stash);
|
378 | |
# _debug("# slurped " . length($got{$_}) . " bytes from $_\n");
|
379 | |
}
|
380 | |
print CT_ORIG_STDOUT $got{stdout}
|
381 | |
if $do_stdout && $do_tee && $localize{stdout};
|
382 | |
print CT_ORIG_STDERR $got{stderr}
|
383 | |
if $do_stderr && $do_tee && $localize{stderr};
|
|
376 |
if ( defined wantarray or ($do_tee && keys %localize) ) {
|
|
377 |
for ( keys %do ) {
|
|
378 |
_relayer($stash->{capture}{$_}, $layers{$_});
|
|
379 |
$got{$_} = _slurp($_, $stash);
|
|
380 |
# _debug("# slurped " . length($got{$_}) . " bytes from $_\n");
|
|
381 |
}
|
|
382 |
print CT_ORIG_STDOUT $got{stdout}
|
|
383 |
if $do_stdout && $do_tee && $localize{stdout};
|
|
384 |
print CT_ORIG_STDERR $got{stderr}
|
|
385 |
if $do_stderr && $do_tee && $localize{stderr};
|
|
386 |
}
|
384 | 387 |
$? = $exit_code;
|
385 | 388 |
$@ = $inner_error if $inner_error;
|
386 | 389 |
die $outer_error if $outer_error;
|
387 | 390 |
# _debug( "# ending _capture_tee with (@_)...\n" );
|
|
391 |
return unless defined wantarray;
|
388 | 392 |
my @return;
|
389 | 393 |
push @return, $got{stdout} if $do_stdout;
|
390 | 394 |
push @return, $got{stderr} if $do_stderr;
|
|
469 | 473 |
filehandles during a capture operation will give unpredictable results.
|
470 | 474 |
Existing IO layers on them may be changed by the capture.
|
471 | 475 |
|
|
476 |
When called in void context, {capture} saves memory and time by
|
|
477 |
not reading back from the capture handles.
|
|
478 |
|
472 | 479 |
== capture_stdout
|
473 | 480 |
|
474 | 481 |
($stdout, @result) = capture_stdout \&code;
|
|
504 | 511 |
|
505 | 512 |
The {tee} function works just like {capture}, except that output is captured
|
506 | 513 |
as well as passed on to the original STDOUT and STDERR.
|
|
514 |
|
|
515 |
When called in void context, {tee} saves memory and time by
|
|
516 |
not reading back from the capture handles, except when the
|
|
517 |
original STDOUT OR STDERR were tied or opened to a scalar
|
|
518 |
handle.
|
507 | 519 |
|
508 | 520 |
== tee_stdout
|
509 | 521 |
|