我有這樣的命令。如何從外部命令結合管道輸出
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
請幫忙。