I am trying to execute this bash
command n python
and try to evaluate the output, based on the output, I want to show my own-defined outputs.
The bash
command I am trying to execute using the python
is:
kubectl get pods --field-selector=status.phase=Failed -n kube-system
everything looks really good and only problem I am having is,
This outputs No resources found
, means there are no resources matching the given criteria (i.e status.phase=Succeeded)
, but that is fine, but the problem is It prints in the terminal. What I want to do is, prints my own-defined output when the actual output is No resources found
, but I can't do that since it already prints that output in the terminal. I even can't use the status_code
to check, it always gives 0
even after the resources are found or not (which is correct) since code has executed successfully. Is there a way that I can filter the output during the executing of the bash
command and gives a condition based on the output to print my own-defined output?
Here is my code snippet:
def subprocess_execute_arr(self):
output = subprocess.call(self)
return output
cmd_failed = ["kubectl", "get", "pods", "--field-selector=status.phase=Failed", "-n", "kube-system"]
failed = execute.subprocess_execute_arr(cmd_failed) //this is where it prints the output in the terminal
output:
No resources found.
PS: Here output is not an error, command has executed correctly but I don't need to print this output.
Any idea how to solve this?