模块subprocess, logging

Subprocess模块运行生成新的流程,连接到输入/输出/错误,并获取他们得返回码

import subprocess
cmd=input(">>:")
res=subprocess.Popen(cmd,shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
a=res.stdout.read()

print(a.decode("gbk"))
print(res.stderr.read().decode("gbk"))


logging 模块提供标准日志输出接口,logging日志分为debug(),info(),warning(),error(),critical() 五个级别
import logging
logging.warning("uses does not exit") #设置日志信息
logging.critical('''server is down ''')
logging.basicConfig(filename="log",level=logging.INFO) #指定日志子文件,设置日志级别
logging.info("test")
logging.basicConfig(format="%(asctime)s %(message)s",datefmt="%m%d%Y %I:%M:%S %p") #配置日志时间
# DEBUG 详细信息,通常用来分析问题
# INFO 正常工作信息
# WARNING 一些意向不到的事情发生,或者一些问题在即将发生。目前软件依旧按预期工作
# ERROR 由于严重的问题,软件没能执行一些功能
# CRITICAL 严重错误,程序本身可能无法继续运行

**********************

logger提供了应用程序可以直接使用的接口;


handler将(logger创建的)日志记录发送到合适的目的输出;


filter提供了细度设备来决定输出哪条日志记录;


formatter决定日志记录的最终输出格式。

 


原文地址:https://www.cnblogs.com/arthas-zht/p/6514484.html