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
subprocess.check_output()
ps -A | grep \'process_name\'
After Python 3.5 you can also use:
import subprocess f = open('test.txt', 'w') process = subprocess.run(['ls', '-la'], stdout=subprocess.PIPE, universal_newlines=True) f.write(process.stdout) f.close()
The execution of the command is blocking and the output will be in process.stdout.