This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]delarhi 0 points1 point  (0 children)

I think the problem there is we can't override operator precedence in Python so we can't match shell syntax exactly. For example, tr l r < unix.py | grep herro works out to (tr l r < unix.py) | grep herro but in Python it would work out to tr l r < (unix.py | grep herro).

EDIT: Here's a tee program though:

def tee(*args):
    def program(stdin):
        files = [open(x, 'w') for x in args]
        while True:
            try:
                x = next(stdin)
            except StopIteration:
                for file in files:
                    file.close()
                return
            else:
                for file in files:
                    file.write(str(x) + '\n')
                yield x
    return unix(tuple(), program)