python读取目录并执行命令

def work():
    pathDir = os.listdir("/proc");
    for elem in pathDir:
        file = None
        name = "/proc/" + elem
        if os.path.isdir(name):
            file = name + "/" + "smaps"
        else:
            continue
        exist = os.path.exists(file)
        if exist == False:
            continue
        cmd = "cat " + file + " |grep Huge |grep 2048"
        print cmd
        os.system(cmd)           # 或是os.system('%s >> b.log' % cmd)

    return
posted @ 2017-10-20 13:46  你的KPI完成了吗  阅读(405)  评论(0)    收藏  举报