Tee does not exit after pipeline it's on has f

2019-06-15 17:00发布

问题:

So, I've got a rather long and involved script intended to be used by people who aren't going to want to dig into anything that goes wrong.

Recently, during testing, the script froze inexplicably. Long story short, I executed a command in a subshell in order to be able to tee stdout and stderr to my log file:

(/path/to/script -i -ran 2>&1; ) | tee -a /path/to/mylogfile

The script was no longer in the process tree, no longer running, and seems to have exited completely because the file that it writes as its last action was there and not open. However, tee remained, obstinately. I killed tee, and the script proceeded merrily on its way. This is the first time this has happend, and I want to know if there's anything I can do to prevent it from happening again. Any ideas would be most appreciated.