From ee29d1febfcb414e9a8b4d162fc923cc704b8178 Mon Sep 17 00:00:00 2001 From: drevicko Date: Thu, 25 Mar 2021 14:56:23 +1100 Subject: [PATCH] Added a note about write file | read file, which can also create a race condition (and the exception that a non-greedy reader like `less` is ok). --- SC2094.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SC2094.md b/SC2094.md index a90557a..73ecd40 100644 --- a/SC2094.md +++ b/SC2094.md @@ -20,6 +20,8 @@ In this case, `grep foo file.txt` will immediately try to read `file.txt` while This is a race condition, and results in the file being partially or (far more likely) entirely truncated. +Note that this can also be a problem when you write to a file and read from it later in the pipe. The second command (which reads the file) may not see all the output of the first. An exception in this case is a non-greedy file reader like `less`, for example `python foo.py 2> errfile.txt | less - errfile.txt` will successfully allow you to see stdout and stderr separately in less. + ### Exceptions You can ignore this error if: