{ Make this readable }

Tuesday, July 20, 2010

/dev/null on Windows

I was trying to run Apache ZooKeeper on Windows the other day. Getting it to run was super easy. I was more interested in running it without any file/snapshot logging.

I did ask around in the forums and I thought letting the "dataDir" directory to point to "/dev/null" would solve the problem. But being a (ahem) Windows user I couldn't quite get the "/dev/null" to work. In Windows the equivalent is "nul" but it doesn't quite work when you try to use it from Java. Some operations work, but some don't.

[Update 1:
Strangely getAbsolutePath() prepends the current directory's path but the file does not get created.
Creating nul:\abc.log throws an exception. But nul:abc.log does not and Java says its absolute path is d:\dump\nul:abc.log but the file is not there. Which means that it is indeed writing to the "null" device. I wonder what I'm missing.]

As usual, the full code is here: http://gist.github.com/484116

Here's the output and it shows what works and what doesn't:


Shantanu Kumar said...

I think the Windows null device name is NUL:

Not D:\somedir\nul:
Just NUL:
Like C: D: etc.

Similarly the console device in Windows is CON:

Ashwin Jayaprakash said...

Yup, that's what I did in very the first line but Java new File("nul:").getAbsolutePath() mysteriously adds a prefix to it.

Shantanu Kumar said...

Looks like a bug in the java.io.File implementation. Would suggest file a bug on the JDK: http://bugreport.sun.com/bugreport/

java.io.File depends on an abstract class called FileSystem, which is implemented as a native library.

Ashwin Jayaprakash said...

I've filed a bug report. Waiting for a confirmation from Oracle.

Amit Sharma said...

Hi did you get solution of your problem?

Ashwin Jayaprakash said...

@Amit - no luck