Je veux capturer la sortie de dpkg --list | grep linux-image
en Python 2.6.5 sur Ubuntu 10.04.Stdout capturé à partir du tube en Python est tronqué
from subprocess import Popen
from subprocess import PIPE
p1 = Popen(["dpkg", "--list"], stdout=PIPE)
p2 = Popen(["grep", "linux-image"], stdin=p1.stdout, stdout=PIPE)
stdout = p2.communicate()[0]
Le contenu de stdout est:
>>> print stdout rc linux-image-2. 2.6.31-14.48 Linux kernel image for version 2.6.31 on x86 ii linux-image-2. 2.6.32-22.36 Linux kernel image for version 2.6.32 on x86 ii linux-image-2. 2.6.32-23.37 Linux kernel image for version 2.6.32 on x86 ii linux-image-2. 2.6.32-24.43 Linux kernel image for version 2.6.32 on x86 ii linux-image-2. 2.6.32-25.44 Linux kernel image for version 2.6.32 on x86 ii linux-image-ge 2.6.32.25.27 Generic Linux kernel image
Cependant, ce n'est pas la même que celle qui dpkg --list | grep linux-image
dans une coquille:
[email protected]:~$ dpkg --list | grep linux-image rc linux-image-2.6.31-14-generic 2.6.31-14.48 Linux kernel image for version 2.6.31 on x86 ii linux-image-2.6.32-22-generic 2.6.32-22.36 Linux kernel image for version 2.6.32 on x86 ii linux-image-2.6.32-23-generic 2.6.32-23.37 Linux kernel image for version 2.6.32 on x86 ii linux-image-2.6.32-24-generic 2.6.32-24.43 Linux kernel image for version 2.6.32 on x86 ii linux-image-2.6.32-25-generic 2.6.32-25.44 Linux kernel image for version 2.6.32 on x86 ii linux-image-generic 2.6.32.25.27 Generic Linux kernel image
En regardant la première ligne, on peut voir que la sortie en Python est tronquée:
rc linux-image-2. 2.6.31-14.48
au lieu de
rc linux-image-2.6.31-14-generic 2.6.31-14.48
Pourquoi faut-il faire cela et est-il un moyen d'obtenir exactement le même résultat en Python?
Cela a résolu mon problème. Merci! Est-ce quelque chose que vous devez savoir ou est-il documenté n'importe où? 'man dpkg 'ne mentionne pas du tout LANG. – cschol
@cschol: Malheureusement, je ne connais aucune documentation; J'ai appris à connaître ce problème ici: http://ubuntuforums.org/showthread.php?p=6943778#post6943778. – unutbu