2

If I run a system command in Jupyter Notebook I would expect that log messages of my console application are shown "immediately" in the notebook. However, it seems that they only occur after the complete process has been finished.

I tried

!D:/long_running_executable_with_log_messages.exe

and

import os
os.system('D:/long_running_executable_with_log_messages.exe')

=>How can I get the output of the system command continuously?

Related question:

Running interactive command line code from Jupyter notebook

Stefan
  • 10,010
  • 7
  • 61
  • 117

1 Answers1

1
from subprocess import Popen, PIPE, CalledProcessError

with Popen(cmd, stdout=PIPE, bufsize=1, universal_newlines=True) as p:
    for line in p.stdout:
        print(line, end='') # process line here

if p.returncode != 0:
    raise CalledProcessError(p.returncode, p.args)

Found at Constantly print Subprocess output while process is running

Stefan
  • 10,010
  • 7
  • 61
  • 117