linux - [Solved-5 Solutions] Python subprocess command with pipe - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
How to use python subprocess command with pipe ?
Linux - Solution 1:
- To use a pipe with the subprocess module, you have to pass shell=True.
- It isn't really advisable for various reasons, not least of which is security.
- Instead, create the ps and grep processes separately, and pipe the output from one into the other, like so:
Linux - Solution 2:
You can use method on subprocess objects.
This method returns in a tuple the standard output and the standard error
Linux - Solution 3:
setting up a pipeline using subprocess:
Linux - Solution 4:
To use 'pgrep' command instead of 'ps -A | grep 'process_name'
Linux - Solution 5:
You can try the pipe functionality in sh.py: