Skip to content

Instantly share code, notes, and snippets.

@DRMacIver
Created November 22, 2011 15:55
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 DRMacIver/1385990 to your computer and use it in GitHub Desktop.
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
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