Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- import time
- import os
- from threading import Thread
- from queue import Queue
- def enqueue_output(proc, queue):
- while not proc.poll():
- line = proc.stdout.readline()
- queue.put(line)
- def main(filepath):
- filepath = os.path.abspath(os.path.expanduser(filepath))
- proc = subprocess.Popen([filepath], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- queue = Queue()
- thread = Thread(target=enqueue_output, args=(proc, queue))
- thread.start()
- while True:
- if queue.qsize():
- line = queue.get(timeout=.1).decode("utf-8").strip()
- print(line)
- else:
- time.sleep(.5)
- if __name__ == "__main__":
- main("sample.sh")
Add Comment
Please, Sign In to add comment