fix freopen breaking pipe redirection
As reported by @xishen , pipe redirection does not work with the HATHOR
reaction and LDEBUG=False
after freopen
, because the original stdout is gone (cc @scamarda)
See https://c-faq.com/stdio/undofreopen.html
To reproduce the problem, run test HATHOR-cbt
using the standard tools/test.sh
script:
./tools/test.sh HATHOR-cbt
While the output should be redirected to temp/HATHOR-cbt/xfitter.log
, in fact after the line ----- End of parameters in YAML format
it goes to the screen instead of this file.
Solution according to https://stackoverflow.com/questions/1908687/how-to-redirect-the-output-back-to-the-screen-after-freopenout-txt-a-stdo
Need to test on macOS: the solution uses unistd.h
, I do not know if it is available on macOS?