linux - Python subprocess command with pipe -


i want use subprocess.check_output() ps -a | grep 'process_name'. tried various solutions far nothing worked. can guide me how it?

to use pipe subprocess module, have pass shell=true.

however, isn't advisable various reasons, not least of security. instead, create ps , grep processes separately, , pipe output 1 other, so:

ps = subprocess.popen(('ps', '-a'), stdout=subprocess.pipe) output = subprocess.check_output(('grep', 'process_name'), stdin=ps.stdout) ps.wait() 

in particular case, however, simple solution call subprocess.check_output(('ps', '-a')) , str.find on output.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -