카테고리 없음

특정 커멘드 결과값 계속 받아오기

flack3r 2019. 1. 16. 22:02

import subprocess
import shlex

def run_command(cmd):
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    while True:
        output = process.stdout.readline()
        if output == '' and process.poll() is not None:
            break

        if output:
            print output
    rc = process.poll()
    return rc

def main():
    print "Catch go"
    cmd = "something"
    run_command(shlex.split(cmd))

if __name__ == '__main__':
    main()