#!/usr/bin/env python3 import sys import time import fcntl import subprocess def file_pop_line(path): try: with open(path, 'rt+') as q: fcntl.lockf(q, fcntl.LOCK_EX) first = q.readline() if first == '': return None rest = q.read() q.seek(0) q.write(rest) q.truncate() return first except FileNotFoundError: return None def main(argv): test_queue = argv[1] while 1: cmd = file_pop_line(test_queue).strip() if cmd is None: time.sleep(5) else: print() print("Executing %s" % cmd) p = subprocess.Popen(['bash', '-c', cmd]) p.wait() print() print("Return code is %d" % p.returncode) print() if __name__ == '__main__': sys.exit(main(sys.argv))