【发布时间】:2009-09-10 11:17:53
【问题描述】:
我有这样的命令。
wmctrl -lp | awk '/gedit/ { print $1 }'
我想要它在 python 脚本中的输出,我试过这段代码
>>> import subprocess
>>> proc = subprocess.Popen(["wmctrl -lp", "|","awk '/gedit/ {print $1}"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> proc.stdout.readline()
'0x0160001b -1 6504 beer-laptop x-nautilus-desktop\n'
>>> proc.stdout.readline()
'0x0352f117 0 6963 beer-laptop How to get output from external command combine with Pipe - Stack Overflow - Chromium\n'
>>> proc.stdout.readline()
'0x01400003 -1 6503 beer-laptop Bottom Expanded Edge Panel\n'
>>>
看来我的代码是错误的,只有 wmctrl -lp 被执行,| awk '{print $1}' 被省略
我的预期输出是0x03800081
$ wmctrl -lp | awk '/gedit/ {print $1}'
0x03800081
请帮忙。
【问题讨论】: