stdoutbytes 524 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python3
  2. import sys
  3. if len(sys.argv) != 2:
  4. print("Usage: stdoutbytes BYTEVALUE", file=sys.stderr)
  5. sys.exit(1)
  6. try:
  7. bval = int(sys.argv[1], 0)
  8. if not (0 <= bval <= 0xFF):
  9. raise ValueError
  10. except ValueError:
  11. print("Invalid BYTEVALUE.", file=sys.stderr)
  12. sys.exit(1)
  13. b = bytes((bval,)) * 2**20
  14. write = sys.stdout.buffer.write
  15. try:
  16. while True:
  17. write(b)
  18. except (BrokenPipeError, KeyboardInterrupt) as e:
  19. sys.exit(0)
  20. except Exception as e:
  21. print("Exception: %s" % str(e), file=sys.stderr)
  22. sys.exit(1)