On trying to run the grep for the output of previous command using popen returning blank without any error
proc1cmd = "grep " + fetchname1
p1 = subprocess.Popen(['kubectl', 'get', 'abr', '-A'], stdout=subprocess.PIPE)
p2 = subprocess.Popen(proc1cmd, shell=True, stdin=p1.stdout, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
p1.stdout.close()
stdout_list = p2.communicate()[0]
stdout_list = stdout_list.decode()
print(p2.stdout)
print(p2.communicate())
output i got:
<_io.BufferedReader name=7>
(b'', b'')
You don't need to concoct a pipeline of kubectl + grep here.
kubectl_output = subprocess.check_output(
["kubectl", "get", "abr", "-A"], encoding="utf-8"
)
matching_lines = [
line for line in kubectl_output.splitlines() if fetchname1 in line
]
print(matching_lines)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.