mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-12-16 02:01:41 +08:00
CleanupTask: Restore STDERR and STDOUT to what they were when the object was created
This commit is contained in:
@@ -42,6 +42,10 @@ sub new {
|
||||
my $self = {
|
||||
task => $task,
|
||||
};
|
||||
open $self->{stdout_copy}, ">&=", *STDOUT
|
||||
or die "Cannot dup stdout: $OS_ERROR";
|
||||
open $self->{stderr_copy}, ">&=", *STDERR
|
||||
or die "Cannot dup stderr: $OS_ERROR";
|
||||
PTDEBUG && _d('Created cleanup task', $task);
|
||||
return bless $self, $class;
|
||||
}
|
||||
@@ -51,6 +55,12 @@ sub DESTROY {
|
||||
my $task = $self->{task};
|
||||
if ( ref $task ) {
|
||||
PTDEBUG && _d('Calling cleanup task', $task);
|
||||
# Temporarily restore STDOUT and STDERR to what they were
|
||||
# when the object was created
|
||||
open local *STDOUT, ">&=", $self->{stdout_copy}
|
||||
if $self->{stdout_copy};
|
||||
open local *STDERR, ">&=", $self->{stderr_copy}
|
||||
if $self->{stderr_copy};
|
||||
$task->();
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user