1 | #!/usr/bin/env python
|
2 | """
|
3 | coproc.py
|
4 | """
|
5 |
|
6 | import sys
|
7 |
|
8 |
|
9 | def main(argv):
|
10 | print >>sys.stderr, argv
|
11 | try:
|
12 | command = argv[1]
|
13 | except IndexError:
|
14 | command = 'upper'
|
15 |
|
16 | if command == 'upper':
|
17 | func = lambda x: x.upper()
|
18 | else:
|
19 | func = lambda x: x.lower()
|
20 |
|
21 | while True:
|
22 | line = sys.stdin.readline()
|
23 | if not line:
|
24 | print >>sys.stderr, 'DONE %s' % command
|
25 | break
|
26 | sys.stdout.write(func(line))
|
27 | # If we don't do this, it hangs forever
|
28 | sys.stdout.flush()
|
29 |
|
30 |
|
31 | if __name__ == '__main__':
|
32 | try:
|
33 | main(sys.argv)
|
34 | except RuntimeError as e:
|
35 | print >>sys.stderr, 'FATAL: %s' % e
|
36 | sys.exit(1)
|