我想抓住
dpkg --list | grep linux-image
在Ubuntu 10.04的Python2.6.5中。
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]
标准的内容是:
>>> 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
但是,这与跑步不同
dpkg—列出| grep linux映像
cschol@blabla:~$ 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
rc linux-image-2. 2.6.31-14.48
而不是
rc linux-image-2.6.31-14-generic 2.6.31-14.48