This code Running shell command and printing the output in real time.
process = subprocess.Popen('yt-dlp https://www.youtube.com/watch?v=spvPvXXu36A', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
output = process.stdout.readline().decode()
if output == '' and process.poll() is not None:
break
if output:
print(output.strip())
rc = process.poll()
if rc == 0:
print("Command succeeded.")
else:
print("Command failed.")