命令行输出的内容重定向保存到文件里

文章目录

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命令,用于同时把输出输出到标准输出设备和保存成文件。


另外,其实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

参考:

猜你喜欢

转载自blog.csdn.net/Castlehe/article/details/126970344
今日推荐