Created
February 14, 2012 10:10
-
-
Save pung96/1825487 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/perl | |
#=============================================================================== | |
# | |
# FILE: intime.pl | |
# | |
# USAGE: ./intime.pl | |
# | |
# DESCRIPTION: | |
# | |
# OPTIONS: --- | |
# REQUIREMENTS: --- | |
# BUGS: --- | |
# NOTES: --- | |
# AUTHOR: Beomsu Chang (bschang), [email protected] | |
# COMPANY: | |
# VERSION: 1.0 | |
# CREATED: 02/14/2012 11:46:48 | |
# REVISION: --- | |
#=============================================================================== | |
use strict; | |
use warnings; | |
my $timelimit = shift @ARGV; | |
my ( @command ) = @ARGV; | |
my $command = join ' ',@command; | |
eval { | |
local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required | |
alarm $timelimit; | |
print $command; | |
open my $com,'-|',$command; | |
while(<$com>){ print }; | |
alarm 0; | |
}; | |
if ($@) { | |
# timed out | |
print "\n\n##########################################################\n"; | |
print STDERR "error: Timeout after $timelimit seconds requesting \n"; | |
print "##########################################################\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment