warum sollten wir verwenden stdout=PIPE in Teilprozess.Popen?

from subprocess import PIPE,Popen

p = Popen("ls -l",shell=True,stderr=PIPE,stdout=PIPE)
(out,err) = p.communicate()
print(out, err)

In über Popen nennen, wenn ich entfernen stdout=PIPE, bin ich immer der Zeilenumbruch nach jedem Eintrag, indem ls -l im Ausgang. Aber wenn die Verwendung stdout=PIPE bekomme ich \n angezeigt, anstatt "newline", wie unten

b'total 67092\n-rw-r--r--  1 root root      171 May 27 09:08 new.py\n-rw-r--r--  1   
    root root       74 May 12 18:14 abcd.conf\n-rwxr-xr-x  1 root root     5948 May 13 13:21 abxyz.sh\ndrwxr-xr-x  2 root root     4096 May 13
12:39 log\ndrwxrwxrwx  3 root root     4096 May 14 16:02
newpy\n-rw-r--r--  1 root root      134 May 27 10:13
pipe.py\n-rw-r--r--  1 root root      155 May 27 10:07
proc.py\ndrwxrwxrwx  3 root root     4096 May 14 14:29 py\ndrwxr-xr-x
16 1000 1000\n' b''

Wie funktioniert PIPE genau funktioniert bei subprocess.Popen? Warum brauchen wir es? Ich bekam richtigen output, ohne Sie auch? Sind wir mit diesem für immer beide stderr, stdout?

InformationsquelleAutor | 2013-05-27
Schreibe einen Kommentar