How to open a Windows named pipe from Java? How to open a Windows named pipe from Java? windows windows

How to open a Windows named pipe from Java?


Use Named Pipes to Communicate Between Java and .Net Processes

Relevant part in the link

try {  // Connect to the pipe  RandomAccessFile pipe = new RandomAccessFile("\\\\.\\pipe\\testpipe", "rw");  String echoText = "Hello word\n";  // write to pipe  pipe.write ( echoText.getBytes() );  // read response  String echoResponse = pipe.readLine();  System.out.println("Response: " + echoResponse );  pipe.close();} catch (Exception e) {  // TODO Auto-generated catch block  e.printStackTrace();}


In windows, named pipes exist but they cannot be created as files in a writeable filesystem and there is no command line tool. They live in a special filesystem and can be created only by using the Win32 API.

Looks like you'll have to resort to native code, or switch from pipes to sockets for IPC - probably the best longterm solution, since it's much more portable.


You can create named pipe using JNA library https://github.com/java-native-access/jna

It is clearly shown in the following test: https://github.com/java-native-access/jna/blob/master/contrib/platform/test/com/sun/jna/platform/win32/Kernel32NamedPipeTest.java

API of JNA wrapper is the same as Win32 hence you will be able to use all the features and power of named pipes on Windows.