I want to use subprocess.check_output() with ps -A | grep 'process_name'.
I tried various solutions but so far nothing worked. Can someone guide me how to do it?
I want to use subprocess.check_output() with ps -A | grep ‘process_name’ . I tried
Share
To use a pipe with the
subprocessmodule, you have to passshell=True.However, this isn’t really advisable for various reasons, not least of which is security. Instead, create the
psandgrepprocesses separately, and pipe the output from one into the other, like so:In your particular case, however, the simple solution is to call
subprocess.check_output(('ps', '-A'))and thenstr.findon the output.