Skip to content

Instantly share code, notes, and snippets.

@dagolden

dagolden/tee3.pl

Created May 13, 2015
Embed
What would you like to do?
#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
use Capture::Tiny 'tee';
use Path::Tiny;
die "Usage: $0 <outfile> <errfile> <command ...>\n"
unless @ARGV > 2;
my ($of, $ef, @cmd) = @ARGV;
my ($out, $err, $rc) = tee { system(@cmd) };
die "Error executing '@cmd': $!" if $rc < 0;
path($of)->spew($out);
path($ef)->spew($err);
exit( $rc & 255 ? 1 : $rc >> 8 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment