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