I am trying to execute this shell command using python
but the problem is, it doesn't give the output even if there is a wrong or not:
This is what I have tried:
get_ns_p1 = subprocess.Popen(['kubectl', 'get', 'ns'], stdout=subprocess.PIPE)
get_ns_p2 = subprocess.Popen(["grep", "-E", "\'(^|\s)"+NAMESPACE+"($|\s)\'"], stdin=get_ns_p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
get_ns_p1.stdout.close() # Allow proc1 to receive a SIGPIPE if proc2 exits.
out_ns, err = get_ns_p2.communicate()
print("output: " + out_ns)
print("error: " + err)
The output looks like:
output:
error:
but in the terminal itseld, it shows an output like this:
Error from server (AlreadyExists): namespaces "namespace-tests" already exists
how can I this error to my err
variable?