python的subprosess模块比os模块更加强大,查了一些资料它的出现就是为了替换老旧的os模块的,以后要多学习一些subprocess模块的东西,最近在学习网络变成,用到了subprocess的一些用法,现在总结一些,以后有新加的都添加都这里面
女神网络编程中也有:http://www.cnblogs.com/Eva-J/articles/8244551.html (粘包中第一个)
import subprocess
res=subprocess.Popen("dir", #把终端需要执行的命令写在这里 对象res就会接受输出的结果
shell=True,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
print(res.stdout.read().decode("gbk"))