ich habe das leidige und schon häufig besprochene Problem mit popen und subprocess eine fließende Ausgabe hinzubekommen.
Ich such jetzt schon gut 3 Stunden aber es scheint einfach keine Lösung zu geben.
Ich habe ein kleines Programm:
Code: Alles auswählen
import time
for i in range(5):
print i
time.sleep(0.5)
Ich stelle hier auch mal meine Testdatei rein in der alle Codesnippets drinnen sind die ich schon probiert hab. Aber nichts will funktionieren.
Im Forum habe ich mir schon fast sämtliche Beiträge zu subprocess durchgelesen. Leider hat nichts geholfen. (Außer dass ich jetzt weis wo gerold wohnt XD)
Ich benutze Debian Linux und Python 2.4 sowie 2.5 zum testen!
Code: Alles auswählen
while 1:
line = proc.stdout.readline()
if not line: break
print line,
Meine Tests:
Code: Alles auswählen
import os
import subprocess
import time
import sys
#import pexpect
proc = subprocess.Popen("python /home/miko/Desktop/python/popen2/testprocess3.py", bufsize=0, shell = True, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
while 1:
line = proc.stdout.readline()
if not line: break
print line,
#cmd = "python -u /home/miko/Desktop/python/popen2/testprocess3.py"
#proc = pexpect.spawn(cmd)
#proc.expect(shell_pro
#print "Process starts"
#r, w = os.popen4('python testprocess.py')
#r.readlines()
#cmd = ['python', '-u' ,'/home/miko/Desktop/python/popen2/testprocess.py']
#proc = subprocess.Popen("python /home/miko/Desktop/python/popen2/testprocess3.py", bufsize=0, shell = True, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
#line="dum"
#while line != "":
# line=proc.stdout.readline()
# sys.stdout.write(line)
#out=proc.stdout.read()
#proc.stdout.flush()
#sys.stdout.flush()
#print out,
#proc.stdout.flush()
#sys.stdout.flush()
#for line in proc.stdout:
# proc.stdout.flush(0)
# print line,
#proc.stdin.close()
#proc.stdout.close()
#proc.stderr.close()
#while True:
#stdout, stderr = proc.communicate()
#print "Ausagabe: ", proc.stdout.read()
#print "Error: ", proc.stderr.read()
#print "Fehler: ", stderr
Miko