Python-subprocess Ausgabe auf stdout

Ich bin mit dem subprocess-Modul zum ausführen von Binärdateien von python.

Zum erfassen der Ausgabe produziert, die von der binary, die ich benutze:

proc = subprocess.Popen (command_args, shell=False, stdout=subprocess.PIPE)
out = proc.communicate()[0]
#print the output of the child process to stdout
print (out)

Was dieser tut, ist drucken die Ausgabe des Prozesses, NACHDEM es fertig ist die Ausführung. Gibt es trotzdem kann ich drucken Sie diese Ausgabe auf stdout, WÄHREND das Programm ausgeführt wird? Ich wirklich brauchen, um zu sehen, was die Ausgabe ist, weil diese Programme können für eine lange Zeit laufen.

Danke für die Hilfe.

  • Macht nix Jungs, ich denke ich habe die Lösung gefunden: Basically you have 3 options: Use threading to read in another thread without blocking the main thread. select on stdout, stderr instead of communicate. This way you can read just when data is available and avoid blocking. Let a library solve this, twisted is a obvious choice.
  • Wenn Sie finden eine andere Antwort, wie stackoverflow.com/questions/4585692/... , bitte verlinken, statt Sie zu duplizieren die Antwort im Kommentar auf deine eigene Frage.
  • Tut mir Leid, dass. Ich dachte, der Punkt in dem Kommentar wurde die destillierte Essenz stackoverflow.com/questions/4585692/... ich werde das im Kopf behalten das nächste mal
InformationsquelleAutor therealtypon | 2011-05-19
Schreibe einen Kommentar