Issue
This may not be the best wording for the question. I am trying to see 2 files at once on my screen. I run:
multitail ~/path/to/somefile.err ~/path/to/somefile.out
I have a python script with the following lines:
sys.stdout = open('~/path/to/somefile.out', 'a')
sys.stderr = open('~/path/to/somefile.err', 'a')
My multitail command seems to only output my .out file, regardless of which order I put the files in the command.
I verified that my script is indeed writing to the files. What is also interesting, was that when I run the following command:
echo "text" >> ~/path/to/somefile.err
All of a sudden I see all the output from the .err file in the multitail screen (including that which didn't show up before)!
What is going on here that I can not see?
P.S. this is my first time using multitail so maybe I overlooked something simple. If it means anything, I am using CentOS 7.
Solution
You need to pass either buffering=0
(for unbuffered) or buffering=1
(for line-buffered - probably what you want) in your call to open
.
The default is buffering=-1
, which is equivalent to something like buffering=512
with a value depending on the system, so nothing will be written to the file until 512 (or whatever) bytes are written.
Alternatively, you could leave buffering
set to its default value, and call .flush()
every time you want the data to appear in the file.
When you use >>
in the shell, that will close the file when the command exits, and closing implies a flush. (You can defer the close by using exec >> file.txt
)
Answered By - o11c