[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
On recent windows fileno return -2 in case of closed stdin, stdout, stde
From: |
Bastien ROUCARIES |
Subject: |
On recent windows fileno return -2 in case of closed stdin, stdout, stderr |
Date: |
Mon, 6 Apr 2020 19:09:51 +0200 |
Hi,
according to
https://docs.microsoft.com/fr-fr/cpp/c-runtime-library/reference/fileno?view=vs-2019
If stdout or stderr is not associated with an output stream (for
example, in a Windows application without a console window), the file
descriptor returned is -2. In previous versions, the file descriptor
returned was -1. This change allows applications to distinguish this
condition from an error.
This should be mentionned in the doc:
A work arround is to create a console at the beginning of the program
and close the window.
if(AllocConsole())
{
freopen ("CONOUT$", "w", stdout);
freopen ("CONOUT$", "w", stderr);
ShowWindow (FindWindowA ("ConsoleWindowClass", NULL), false);
}
See also https://github.com/rprichard/win32-console-docs for list of
bug due to closing console handle.
Bastien
- On recent windows fileno return -2 in case of closed stdin, stdout, stderr,
Bastien ROUCARIES <=