Windows does have a concept for null devices as detailed here, here or here for example. All examples that I can find are about redirecting streams.
While porting a script from Linux to Windows, I came across something odd: If nul
is opened like a file, I an write to it, close it, re-open it and read the data back. Sometimes. Checking the working directory, I can see a file named nul
being created and growing as I write data to it. Ironically, I can not delete it from the explorer, only from the command line.
Windows 10 comes with its a native implementation of OpenSSH nowadays. I wanted to use an old trick: When it is looking for the known_hosts
file, I want to point it to a null device instead. On Linux, this looks as follows: ssh -o UserKnownHostsFile=/dev/null user@host
. On Windows, I tested it as follows: ssh -o UserKnownHostsFile=nul user@host
. I got a file named nul
containing the hosts. I also tried NUL
, null
and NULL
with the same result. Trying to point to \Device\Null
or /Device/Null
causes ssh
to complain that it can not find/open those files.
How do I correctly use and/or point to the null device on Windows (10)?
The JS crowd has a solution: I need to point to
\\.\NUL
. This is the actual name or path of the null device, apparently.