Skip to content

Instantly share code, notes, and snippets.

@dagolden
Created May 13, 2015 18:28
Show Gist options
  • Save dagolden/c5e560e5916bd9827b81 to your computer and use it in GitHub Desktop.
Save dagolden/c5e560e5916bd9827b81 to your computer and use it in GitHub Desktop.
#!/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