用于python的Unix tee命令

pyteetime的Python项目详细描述


Unix命令tee分割程序的输出,以便两者兼而有之 显示在屏幕上并写入文件。pyteetime包 在Python中提供这样的功能。它是以原作为基础的 来自A. Peck的代码,带有 添加了一些类方法。在

用法:

运行下面列出的示例脚本tee-test.py

frompyteetimeimportteeimportsysprint('This prologue will appear on screen but not in a logfile')LOGFILE=tee.stdout_start(append=False)# STDOUT# from now on, all output is also copied to the logfiletee.stderr_start(append=False)# STDERR# from now on, all output to STDERR is also copied to stderr.logprint('This text will appear on screen and also in the logfile')print('This will appear on screen and also in stderr.log',file=sys.stderr)# input from keyboard does not go to logfile:answer=input('Enter something!\n')# show the input to make sure it also goes into the logfile:print('The user typed: %s'%(answer))# data written to a file is not copied to the logfile:DATAFILE=open('tee-test.dat','w+')print(list(range(5)),file=DATAFILE)DATAFILE.close()print('This goes to the logfile but will not appear on screen',file=LOGFILE)tee.stdout_stop()# from now on, output to STDOUT will not go to stdout.log anymoretee.stderr_stop()# from now on, output to STDERR will not go to stderr.log anymoreprint('This epilogue will appear on screen but not in a logfile')

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
使用JDBC的java参数化查询   java如何使用imap文件夹的UIDVality和HIGHESTMODSEQ同步电子邮件   java GWT+Eclipse+外部JAR文件   java在膨胀的布局上创建onClick事件   java JTree显示驱动器根本不显示   接收java。sql。SQLException:调用数据库函数时出现无效列索引错误   cassandra使用Datastax Java驱动程序进行数据块写入   java应用程序在drools工作台上触发规则   java将Windows键重新指定给键盘快捷键   java整数划分为和和和积   java如何让JDialog onTop只为他的父母使用?   java如何拥有具有特定关联方法的常量   java是否可以使用icu4j UnicodeSet类代替正则表达式进行模式匹配?   java如何比较数组的相反索引值,以及基于嵌套for循环的条件进行删除?   如果我有文件名和带有文件夹ID的Google drive文件夹完整URL,如何从Selenium Webdriver java脚本访问Google drive文件?   java变量作为图表中的参数   鼠标左键点击指针下的精灵坐标偏移补偿问题   java JDBC库在Android Studio中不工作   Play Framework中的“groovy.lang.MissingFieldException:没有这样的字段:类的元类:java.lang.class”错误   java从XML中读取子元素作为字段值