subprocess模块

#subprocess模块:启子进程模块 import subprocess obj=subprocess.Popen('tasklist',shell=True, #shell=True调用命令解释器来解释前面的命令,发信号并不执行 stdout=subprocess.PIPE, #PIPE管道 stderr=subprocess.PIPE, #放入报错信息 ) print(obj.stdout.read().decode('gbk')) #只能取一次值,取出格式是b格式 import subprocess obj=subprocess.Popen('list',shell=True, stdout=subprocess.PIPE, #PIPE管道 stderr=subprocess.PIPE, #放入报错信息 ) print(obj.stderr.read().decode('gbk')) #只能取一次值,取出格式是b格式 import subprocess obj=subprocess.Popen('ps aux |grep python',shell=True, stdout=subprocess.PIPE, #PIPE管道 stderr=subprocess.PIPE, #放入报错信息 ) print(obj.stdout.read()) import subprocess #同上 obj1=subprocess.Popen('ps aux ',shell=True, stdout=subprocess.PIPE, #PIPE管道 stderr=subprocess.PIPE, #放入报错信息 ) obj2=subprocess.Popen('grep python ',shell=True, stdin=obj1.stdout, stdout=subprocess.PIPE, #PIPE管道 stderr=subprocess.PIPE, #放入报错信息 ) print(obj2.stdout.read())
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章