| 18 | |
| 19 | |
| 20 | def main(file, cmd): |
| 21 | print(cmd, "writing to", file) |
| 22 | out = open(file, "w") |
| 23 | count = 0 |
| 24 | process = subprocess.Popen(cmd, |
| 25 | stderr=subprocess.STDOUT, |
| 26 | stdout=subprocess.PIPE) |
| 27 | |
| 28 | start = datetime.now() |
| 29 | nextPrint = datetime.now() + timedelta(seconds=1) |
| 30 | # wait for the process to terminate |
| 31 | pout = process.stdout |
| 32 | line = pout.readline() |
| 33 | while line: |
| 34 | line = line.decode('utf-8') |
| 35 | count = count + 1 |
| 36 | if datetime.now() > nextPrint: |
| 37 | diff = datetime.now() - start |
| 38 | sys.stdout.write(f"\r{diff.seconds} seconds {count} log lines") |
| 39 | sys.stdout.flush() |
| 40 | nextPrint = datetime.now() + timedelta(seconds=10) |
| 41 | out.write(line) |
| 42 | line = pout.readline() |
| 43 | out.close() |
| 44 | errcode = process.wait() |
| 45 | diff = datetime.now() - start |
| 46 | sys.stdout.write(f"\r{diff.seconds} seconds {count} log lines") |
| 47 | print() |
| 48 | print(cmd, "done", errcode) |
| 49 | return errcode |
| 50 | |
| 51 | |
| 52 | if __name__ == "__main__": |