tags:

views:

8001

answers:

4

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
@Jim: Interesting - I didn't know you could write to paths off /dev/null as if it were a directory. Hmm.
Jon Skeet
On Ubuntu:echo blah > /dev/null.txtbash: /dev/null.txt: Permission deniedMaybe this is something specific to your system...
catphive
@capthive: There's a difference between /dev/null.txt and /dev/null/foo.txt.
Jon Skeet
@Jim: are you using Reiser4?
ninjalj
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
+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
+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
Of course Jon Skeet is correct. Thank you for stating an obvious and universal truth :)
Martinho Fernandes
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