Bash: log stdout and stderr while preserving order and provenance

后端 未结 2 363
暗喜
暗喜 2020-12-18 16:09

It\'s fairly simple to log both the stdout and the stderr of a command to a log file:

./foo.sh &> log.txt

The problem is that when i

相关标签:
2条回答
  • 2020-12-18 16:26

    maybe you are looking for script it records both stdout, stderr and the commands...it starts a new shell in which it records everything (or use -c _cmd_)

     $ script tx1
    

    your color() function breaks order because sed is buffering...

    0 讨论(0)
  • 2020-12-18 16:40

    How about redirecting stderr to ./tmperr and stdout to ./tmpout, now run two scripts in the background that each continuously read a single line from tmperr or tmpout and then remove that line? This is obviously less than ideal, but if there is a decent delay in the actual foo.sh script, this should work out.

    0 讨论(0)
提交回复
热议问题