Created
November 22, 2011 15:55
-
-
Save DRMacIver/1385990 to your computer and use it in GitHub Desktop.
Run a command with limited STDOUT. Usage: write_limiter some cmd goes here
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
launching_pid = Process.pid | |
reader, writer = IO.pipe | |
MAX_WRITE = 10000 | |
if fork | |
reader.close | |
$stdout.reopen(writer) | |
exec *ARGV | |
else | |
counter = 0 | |
writer.close | |
while c = reader.getc | |
counter += 1 | |
if counter > MAX_WRITE | |
Process.kill("KILL", launching_pid) | |
break | |
else | |
$stdout.putc c | |
end | |
end | |
reader.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment