#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import subprocess


def exec_cmd(cmd):
    proc = subprocess.Popen(
        cmd,
        shell=True,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT)

    while True:
        line = proc.stdout.readline()
        if line:
            yield line
        if not line and proc.poll() is not None:
            break


if __name__ == '__main__':
    # sys.srgv != 1ではないので注意
    if len(sys.argv) != 2:
        print "ERROR: Argument number is not 1!"
        exit(1)

    # 引数がint型である＋1以上である場合はOK
    if sys.argv[1].isdigit() and int(sys.argv[1]) >= 1:
        cmd = 'head -n' + ' ' + sys.argv[1] + ' ' + 'hightemp.txt'
        for line in exec_cmd(cmd):
            sys.stdout.write(line)
    else:
        print "ERROR: Argument type is not integer! or Argument is less than 0!"
        exit(2)
