Ich hab eine Frage bezüglich der beiden oben genannten Befehle.
Und zwar, ich muss mittels eines der beiden Befehle popen() bzw. getoutput() ein Programm ausführen. Dieses Programm jedoch läuft sehr lange (es ist ein programm zum encoden).
Ich möchte mit Python nun dieses Programm immer wieder ausführen für alle Dateien im Verzeichnis. Soweit kein Problem.
Mein Problem / Meine Frage setzt bei der Ausgabe dieses encoder-Programms an. Ich habe schon diverse Befehle ausprobiert.
Ich möchte, dass wenn der Encoder aufgerufen wird die Ausgabe des Programms auch auf dem Bildschirm erscheint, und zwar sofort! Im Moment gibt Python den Anfang der Ausgabe aus, und erst wenn das Programm terminiert wird die restliche Ausgabe auf den Bildschirm geschrieben. Ich weiß jedoch, dass das Programm ständig eine Fortschrittsanzeige aktualisiert, die wird jedoch erst angezeigt wenn das Programm sowieso beendet ist. Wie kann ich nun machen, dass der Fortschritt mir auch in python sofort ohne Pufferung o.ä. angezeigt wird?
Code: Alles auswählen
#!/usr/bin/env python
import glob, time, os, commands
if __name__ == "__main__":
log = open("realcap.log", 'w')
encoder = "mencoder -ovc lavc -lavcopts vcodec=mpeg4 -oac mp3lame -o %s %s"
filelist = glob.glob("ITC2*.rm")
urllist = []
print "The following RealMedia files were found:"
print " ".join(filelist), "\n"
print time.ctime(), "\tStarted capturing of %d RealMedia files" % len(filelist)
print >> log, time.ctime(), "\tStarted capturing of %d RealMedia files" % len(filelist)
for file in filelist:
f = open(file, 'r')
url = f.readline()
urllist += [url]
f.close()
print "".join(urllist)
for url in urllist:
url = url.replace("\r\n", "")
filename = url.split("?")[0]
filename = "cap_" + filename[filename.rfind("/")+1:] + ".avi"
command = encoder % (filename, url)
print "Fetching RealVideo Stream from:", url
print time.ctime(), "\tCapturing", filename, "started"
print >> log, time.ctime(), "\tCapturing", filename, "started"
print os.popen(command).read()
#for line in os.popen(command).readlines():
# print line,
#print commands.getoutput(command)
#print "".join(os.popen(command).readlines())
print >> log, time.ctime(), "\tCapturing", filename, "finished"
print time.ctime(), "\tCapturing", filename, "finished"
print >> log, time.ctime(), "\tFinished capture process"
print time.ctime(), "\tFinished capture process"
log.close()
Code: Alles auswählen
print os.popen(command).read()
#for line in os.popen(command).readlines():
# print line,
#print commands.getoutput(command)
#print "".join(os.popen(command).readlines())
hiroki