如何在没有 tee 的情况下将输出重定向到日志文件?正常重定向不起作用

Aqu*_*wer 2 command-line log redirect tee

为什么不使用三通?因为输出的终端渲染使应用程序运行速度变慢。

出于某种原因,这不起作用:

application 2>&1 >"$logFile"
Run Code Online (Sandbox Code Playgroud)

输出一直到终端..

edw*_*win 6

您已重定向stderrstdout(终端),然后您已重定向stdout到一个文件。总之,您还没有重定向stderr到该文件:

  1. stderr -> stdout,stderr前往终端。
  2. stdout -> $logfilestdout转到$logfile

尝试使用以下方法:

application >"$logfile" 2>&1
Run Code Online (Sandbox Code Playgroud)

注意顺序很重要:

  1. stdout -> $logfilestdout$logfile
  2. stderr -> stdout -> $logfile,stderr转到stdout与 相同$logfile