git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Execute complex shell commands within python and obtain the output.


Hi,

I try to execute some complex shell commands with in python and obtain 
the output, I tried the following method:

For python 3.x:

import subprocess
cmd= some_complex_command_with_pipe_and_others
ps = subprocess.Popen
(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
output = ps.communicate()[0].decode('utf8')

Is this the correct usage for this case?

Regards