Created
October 10, 2012 03:08
-
-
Save Cside/3862937 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Usage: | |
# $ perl fork.pl 'ssh XXX@XXXX "some_heavy_command"' | |
use strict; | |
use warnings; | |
use Capture::Tiny; | |
my $cmd = shift || die 'no command.'; | |
my $pid = fork; | |
if (defined $pid && $pid == 0) { | |
my $out = Capture::Tiny::capture_merged { | |
system $cmd; | |
}; | |
print <<"..."; | |
# ==================================== | |
# $cmd | |
# ==================================== | |
$out | |
... | |
exit 1; | |
} elsif (! defined $pid) { | |
die "couldn't not fork"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment