import subprocess lCMD = "for /l %x in (1, 1, 5) do echo %x && ping 127.0.0.1 -n 2" lCMD = "git status" proc = subprocess.Popen(f'cmd /c {lCMD}', stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # proc = subprocess.Popen('notepad', stdout=subprocess.PIPE, stderr=subprocess.STDOUT) #proc = subprocess.Popen('cmd /c git status', stdout=subprocess.PIPE, stderr=subprocess.STDOUT) #proc = subprocess.run(f'cmd /c {lCMD}', stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print(123) #import pdb #pdb.set_trace() #tmp = proc.stdout.read() lListenBool = True while lListenBool: tmp = proc.stdout.readline() if tmp == b"": lListenBool = False #tmp = proc.stdout #print(tmp) print(tmp.decode("cp866")) print("Happy end")