-
Notifications
You must be signed in to change notification settings - Fork 9
/
tee.py
executable file
·34 lines (26 loc) · 1 KB
/
tee.py
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
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# "THE JUICE-WARE LICENSE" (Revision 42)
#
# <[email protected]> wrote this file. As long as you
# keep this notice, you can do whatever you want with this stuff.
# If we meet someday, and you think this stuff is worth it, you
# can buy me a glass of juice in return. Yegor Derevenets
import argparse, sys
def main():
parser = argparse.ArgumentParser(description='Copy stdin to stdout and to the given files.')
parser.add_argument('--append', action='store_true', help='Append to the given files, do not overwrite them.')
parser.add_argument('file', nargs='*', help='File.')
args = parser.parse_args()
mode = args.append and 'a' or 'w'
files = [sys.stdout] + [open(filename, mode) for filename in args.file]
while True:
line = sys.stdin.readline()
if not line:
break
for file in files:
file.write(line)
for file in files[1:]:
file.close()
if __name__ == '__main__':
main()