def shell_cmd(cmd):
print('$ ' + cmd)
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = p.communicate()
return p.returncode, stdout, stderr
来源:oschina
链接:https://my.oschina.net/redhands/blog/3157551