Can't open console device file `CONOUT$` on windows
CONOUT$
is similar to /dev/tty
. You need to access it if you want to write to the terminal when the standard streams are redirected.
However, with GHC on Windows openFile "CONOUT$" WriteMode
throws an exception (does not exist).
From what I understand, the issue stems from using getDevicePath
at https://gitlab.haskell.org/ghc/ghc/-/blob/626652f7c172f307bd87afaee59c7f0e2825c55d/libraries/base/GHC/IO/Windows/Handle.hsc#L858, which maps the device name to "\\\\?\\UNC\\.\\CONOUT$"
Using e.g. System.Win32.File.createFile "CONOUT$" 0 0 Nothing oPEN_EXISTING 0 Nothing
directly seems to work.
I haven't tried, but I assume other console related device files are affected in the same way.
I lack the Window expertise to be in a position to suggest a fix for this issue.
https://learn.microsoft.com/en-us/windows/console/console-handles
Steps to reproduce
ghci> import System.IO
ghci> openFile "CONOUT$" WriteMode
Expected behavior
A file handle is returned.
Environment
- GHC version used: 9.6.1
Optional:
- Operating System: Windows 10
- System Architecture: x64