What is the equivalent to /dev/null in Windows?
+42
A:
I think you want NUL
.
For example:
type c:\autoexec.bat > NUL
doesn't create a file.
Jon Skeet
2008-11-23 23:30:34
@Jim: Interesting - I didn't know you could write to paths off /dev/null as if it were a directory. Hmm.
Jon Skeet
2010-03-19 18:33:08
On Ubuntu:echo blah > /dev/null.txtbash: /dev/null.txt: Permission deniedMaybe this is something specific to your system...
catphive
2010-04-26 23:56:12
@capthive: There's a difference between /dev/null.txt and /dev/null/foo.txt.
Jon Skeet
2010-04-27 05:26:12
@Jim: are you using Reiser4?
ninjalj
2010-07-21 20:50:58
I just looked at this again, and I retract my original statement. I was doing the write in code, and the error was getting swallowed.I'm deleting it so no one accidentally takes it as the truth.
Jim Hunziker
2010-07-22 19:30:20
+11
A:
According to this message on the GCC mailing list, you can use the file "nul" instead of /dev/null:
#include <stdio.h>
int main ()
{
FILE* outfile = fopen ("/dev/null", "w");
if (outfile == NULL)
{
fputs ("could not open '/dev/null'", stderr);
}
outfile = fopen ("nul", "w");
if (outfile == NULL)
{
fputs ("could not open 'nul'", stderr);
}
return 0;
}
(Credits to Danny for this code; copy-pasted from his message.)
You can also use this special "nul" file through redirection.
strager
2008-11-23 23:32:55
+4
A:
Jon Skeet is correct. Here is the Nul Device Driver page in the Windows Embedded docs (i have no idea why its not somewhere else...) HEre is another
Foredecker
2008-11-24 01:31:00
Of course Jon Skeet is correct. Thank you for stating an obvious and universal truth :)
Martinho Fernandes
2009-02-21 03:41:47
A:
I did a small experiment on Windows from a Java point of view. Results were a bit confusing. Anyone else had any luck with this?
Ashwin Jayaprakash
2010-07-21 20:39:54