It might be a buffering issue. Dialog
can't show anything until the child process (youtube-dl
) flushes its stdout/stderr buffers. The following works:
#!/usr/bin/env python3
import sys
from subprocess import Popen, PIPE, STDOUT
from dialog import Dialog # $ pip install pythondialog
d = Dialog(dialog="dialog")
d.set_background_title("Random title")
with Popen([sys.executable or "python", "-u", "-c", r"""import sys, time
for i in range(100):
print(i)
if i % 10 == 0:
sys.stderr.write('.\n')
time.sleep(.1)
"""], stdout=PIPE, stderr=STDOUT, bufsize=0) as p:
d.progressbox(fd=p.stdout.fileno(), text="youtube-dl output:")
bufsize=0
disables buffering on Python (parent) side. -u
makes child's streams unbuffered (line-buffered on Python 3).