文章目录
1. linux
执行命令,不管是python还是c++,只要是输出在命令行里的,就可以使用重定向把输出的内容保存到一个文件里。
例如:
python3 tools/train.py -c configs/rec/rec_icdar15_train.yml 2>&1 | tee train_rec.log
./build/bin/interactiveTubeSegExample 2>&1 | tee output.log
关于这里训练的 2>&1 | tee
命令,意思如下
参考中文博客:
Linux shell中2>&1的含义解释 (全网最全,看完就懂)
所以 2>&1 就是标准输出和标准错误输出
参考菜鸟教程-linux tee
参考英语博客:
What does 2>&1 | tee mean?
2. windows
例如运行命令:
D:/XXXX/build/bin/interactiveSegExample.exe >>C:/third/XXXX/chenlinxi/output.log 2>&1
- 但是这样执行会有个问题,cmd里就没有输出信息了,全都写到output.log里去了。。。
其实在windows下也可以使用和linux一样的tee命令,用于同时把输出输出到标准输出设备和保存成文件。
- 在http://sourceforge.net/projects/unxutils/?source=dlp 下载UnxUtils.zip,将tee.exe复制到system32目录下即可使用。
另外,其实windows下除了cmd之外,powershell也有tee命令,但是似乎没有上面那种安装包的tee好用
PS C:\Documents and Settings\Administrator> help Tee-Object
NAME
Tee-Object
SYNOPSIS
Saves command output in a file or variable and displays it in the console.
C:>get-process | tee -filepath C:\file.txt
参考:
- windows控制台重定向输出,跳过控制台重定向信息的处理
- windows下tee指令
- StackExchange:tee for Windows?