Пример #1
0
def main():
    """The main function
    """
    signal.signal(signal.SIGINT, sigint_handler)
    const.setmode([sys.stdin, sys.stdout])

    if len(sys.argv) == 1:
        copy_file_to_stdout(sys.stdin)
        sys.exit(0)

    if sys.argv[1] == '-h':
        print(__doc__)
        sys.exit(0)

    file_names = sys.argv[1:]
    for file_name in file_names:
        try:
            file_ = open(file_name, 'rb')
            copy_file_to_stdout(file_)
            file_.close()
            # sys.stdout.write(open(file_).read())
        except IOError as error:
            sys.stderr.write('fileread.py: {}\n'.format(error))
Пример #2
0
def main():
    """The main function
    """
    signal.signal(signal.SIGINT, sigint_handler)
    const.setmode([sys.stdin, sys.stdout])
    error_message = (
        "Filewrite.py: missing operand specifiers the file.\n"
        + 'Get more information on the command: "filewrite.py -h\n'
    )
    if len(sys.argv) == 1:
        sys.stderr.write(error_message)
        sys.exit(1)
    if sys.argv[1] == "-h":
        print(__doc__)
        sys.exit(0)
    try:
        file_ = open(sys.argv[1], "wb")
        copy_stdin_to_file(file_)
        file_.close()
    except IOError as error:
        sys.stderr.write("filewrite.py: {}\n".format(error))
    else:
        sys.exit(0)
    sys.exit(1)