>I still think that we should not call GetFileInformationByHandle() >when it comes to an argument that we know will fail, ...
Our program calls function freopen() (this function is used in file src\backend\utils\error\elog.c). So we don't know exactly that GetFileInformationByHandle() will fails for stdin/stdout/stderr.
Ior illustration, I attached small example (test.c) for this case: 1) GetFileInformationByHandle() for "stdout" works without error; 2) file "1.txt" after running test contains:
Sample string attributes = 0x2020, file size = 15
We can check for redirection without calling GetFileInformationByHandle(), please consider the attached patch.