-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"failed to write to console" exception on Windows when writing to NUL-redirected file handle #2080
Comments
Thanks for reporting but I wasn't able to repro the issue: #define FMT_UNICODE 1
#define FMT_HEADER_ONLY
#include <fmt/format.h>
int main() {
fmt::print("crash!\n");
}
doesn't throw an exception and prints nothing. Same with What Windows version, compiler and compiler options do you use? |
Apologies for the incomplete repro steps. Are you sure the process in your example isn't throwing an exception? I get an exception with the source and compile flags you list. I'd double-check the process' exit status ( You could also add
Windows 10 x64, version 20H2
|
I can repro with |
Fixed in 9ec5592. Thanks again for catching this. |
This fixes some bugs when piping to /dev/null. (see fmtlib/fmt#2080)
This fixes some bugs when piping to /dev/null. (see fmtlib/fmt#2080)
On Windows, fmtlib can throw an exception when writing to a
FILE*
handle that's been redirected to theNUL
device (Windows' equivalent of/dev/null
).This occurs when fmtlib is in unicode mode -- e.g. you're building with Visual Studio with
FMT_UNICODE
defined, or with clang -- because theWriteConsoleW()
function fmtlib calls will fail if it's passed a file handle that's not actually a console. Unfortunately on Windows_isatty()
is not a robust test for determining if a given fd is a console.I would suggest calling
GetConsoleMode()
instead (or perhaps in addition to the_isatty
check, depending on your level of paranoia!). This is how the UCRT itself determine whether it should callWriteConsoleW
-- if you have the Windows SDK installed, you can check the source atSource/<version>/ucrt/lowio/write.cpp
.To repro:
The text was updated successfully, but these errors were encountered: