1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 r"""C{cat FILENAME}
19
20 Each line of the file named by C{FILENAME} is written to output.
21 Newline characters (\n) are omitted. The C{cat} command takes no
22 input.
23 """
24
25 import sys
26
27 import osh.core
28
29
32
33
35 r"""Each line of the file named by C{filename} is written to output.
36 Newline characters (\n) are omitted. C{cat} takes no input.
37 """
38 return _Cat().process_args(filename)
39
40 -class _Cat(osh.core.Generator):
41
42 _filename = None
43
44
45
46
49
50
51
52
55
57 args = self.args()
58 self._filename = args.next_string()
59 if not self._filename:
60 self.usage()
61
62
63
64
66 file = open(self._filename, 'r')
67 try:
68 eof = False
69 while not eof:
70 line = file.readline()
71 if line:
72 if line.endswith('\n'):
73 line = line[:-1]
74 self.send(line)
75 else:
76 eof = True
77 finally:
78 file.close()
79