将程序输出重定向到文件但不在运行时结束时

Redirect program output to a file but not at the end of the runtime

我想将程序的输出重定向到 Linux 控制台中的文件。我找到了使用“>”命令的想法。但这对我不起作用。 我需要程序运行期间的输出,而不是运行结束时的输出。因为程序将进度(百分比)流式传输到标准输出。我无法为 Linux 系统安装新工具。

程序执行更新功能:

**预期的输出是: (百分比在程序中移动((从 0 -100 %))

# erase 
# load file XXX
# 100%
# erase 
# load file XXX
# 100%

仅记录程序末尾的 100% 信息。不是在节目 运行 期间。对我来说,在程序运行时和结束时获取百分比信息很重要。我想在独立的 GUI 中可视化百分比。

您试过通过管道传送到 tee 吗?这里有一些例子。

echo "text" | tee /home/yourusername/file
bash somescript.sh | tee /home/yourusername/somescript.log

怎么样:

$ nohup program > output.txt ; tail -f output.txt
  • nohup 在后台运行 program 并将其输出重定向到文件
  • tail -f 在屏幕上流式传输文件结尾

这当然意味着当 运行 时您无法与 program 互动。