Python: how to get the final output of multiple system commands?

python, subprocess

Solution

Just pass the `shell=True` option to subprocess

import subprocess
subprocess.check_output('ps -ef | grep something | wc -l', shell=True)

Problem

There are many posts here on SO, like this one: Store output of subprocess.Popen call in a string There is problem with complicated commands. For example, if I need to get output from this ps -ef|grep something|wc -l Subprocess won't do the job, because argument for subprocess is [name of program, arguments], so it is not possible to use more sophisicated commands (more programs, pipes, etc.). Is there way to capture the output of a chain of multiple commands?

Original source

Related problems