0

I need to run a long time command and get the output in live.

As an example, in the above code, I would like to get the "hello" stdout before waiting 20s to terminate the command:

import subprocess
script = '''"
import time
print('hello')
time.sleep(20)
print('OK')
"'''
process = subprocess.Popen(['python', '-c', script], stdout=subprocess.PIPE)

Do you have any idea ? Many thanks for your help.

Franofcholet
  • 81
  • 1
  • 3
  • 7

0 Answers0