Execute complex shell commands within python and obtain the output.
Hongyi Zhao
hongyi.zhao at gmail.com
Mon Sep 2 09:20:25 EDT 2019
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
More information about the Python-list
mailing list