Skip to content

Instantly share code, notes, and snippets.

@kazuho
Created October 23, 2017 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazuho/474bc4a15f8e2a0bb2d7cb4a921b708a to your computer and use it in GitHub Desktop.
Save kazuho/474bc4a15f8e2a0bb2d7cb4a921b708a to your computer and use it in GitHub Desktop.
failed after 2556 iterations: at tmp/runprog.pl line 15, <$fh> line 1.
use File::Temp qw(tempfile);
sub run_prog {
my $cmd = shift;
my ($tempfh, $tempfn) = tempfile(UNLINK => 1);
my $stderr = `$cmd 2>&1 > $tempfn`;
my $stdout = do { local $/; <$tempfh> };
# close $tempfh; # これがないと、いずれ too many open files になる
return ($stderr, $stdout);
}
my ($stderr, $stdout);
for my $i (1..10000) {
($stderr, $stdout) = run_prog("/bin/echo Hi");
die "failed after $i iterations:$!" unless $stdout eq "Hi\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment