linux - bash 将输出重定向到文件,但结果不完整

标签 linux bash redirect

重定向命令输出的问题已经被问过很多次了,但是我有一个奇怪的行为。我正在使用带有版本的 bash shell (debian) 4.3.30(1)-release 并尝试将输出重定向到文件,但并非所有内容都记录在文件中。 我尝试运行的 bin 文件是 linux 的 Sauce-connectv4.4.1(在互联网上公开的 Saucelabs 客户端)

如果我运行

#sudo ./bin/sc --doctor

它向我展示了完整的线条
它打印:

INFO: resolved to '23.42.27.27'
INFO: resolving 'g2.symcb.com' using
DNS server '10.0.0.5'... (followed by other line)
INFO: 'google.com' is not in hosts file
INFO: URL https://google.com can be reached

但是,如果我使用以下命令将相同的命令重定向到文件

#sudo ./bin/sc --doctor > alloutput.txt 2>&1

然后做

#cat alloutput.txt

记录了相同的命令输出,但已弃用,如下所示:

INFO: resolved to '23.42.2me@mymachine:/opt/$

它的行不完整,并且后面的下一行甚至没有记录(丢失)。

我尝试过使用 >> 进行附加,它也有同样的问题。使用 command &> alloutput.txt 也不会打印全部内容。谁能指出如何将上述命令的所有行完全记录到文本文件中?

更新

In the end I manage to use the native binary logging by using --log alloutput.txt where it completely provide me with the correct output. However I let this issue open as I am still wondering why one misses some information/lines by doing an output redirection

最佳答案

你应该尝试这个:stdbuf -o0

喜欢:

stdbuf -o0  ./bin/sc --doctor 2>&1 | tee -a alloutput.txt

关于linux - bash 将输出重定向到文件,但结果不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40788751/

相关文章:

reactjs - 在react-router-dom中重定向?

javascript - 需要在 url 访问时登录

c - 管道在 Linux 中是如何工作的?

python - 如何在使用 python 的 ssh 登录的命令行参数中接受密码

linux - bash代码有问题

bash - git push commit 显示错误 : unable to push to unqualified destination

linux - bash脚本中grep单行的shell脚本

linux - GLX 视觉和 FBconfig 之间有什么区别?

bash - 如何修剪每第n行?

php - 重定向循环 (HTTP_REFERER)