Normalerweise verwende ich sehr einfach subprocess.check_output
:Python check_output druckt aber nicht speichert in var
process = subprocess.check_output("ps aux", shell=True)
print process #display the list of process
Wenn ich fürchte, es ist etwas in stderr
ist, verwende ich es wie folgt aus:
process = subprocess.check_output("ps aux 2> /dev/null", shell=True)
print process #display the list of process
Aber ich habe ein Problem mit nginx -V
:
modules = subprocess.check_output("nginx -V", shell=True) #display the result
print modules #empty
modules = subprocess.check_output("nginx -V 2> /dev/null", shell=True) #display nothing
print modules #empty
Warum ist der Befehl nginx -V
Verhalten sich anders (alle Drucken in stderr
)? Wie kann ich einen Workaround mit "subprocess.check_output" erstellen?
zum Umschalten Es könnte sein, dass ein Prozess speziell an das Terminal Druck wird es ausgeführt wird, auf statt der normalen Kanäle. – languitar