File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Reading from a Named Pipe File (Solaris 2.6) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading from a Named Pipe File (Solaris 2.6)" Watch "Reading from a Named Pipe File (Solaris 2.6)" New topic
Author

Reading from a Named Pipe File (Solaris 2.6)

Billy Kim
Greenhorn

Joined: Aug 13, 2002
Posts: 3
I posted my issue before, yet with no responses, and now I've found the real issue. Here we go...
I'm having problems reading from this named pipe file on Solaris 2.6. Below is the output of an ls -l on the named pipe. notice that it has a "p" as the first character instead of a "-" for a regular file and at the end of the named pipe's filename is a "|":
prw-rw-rw kbdrespipe|
The code will ALWAYS fail on the FileReader statement in the code below, yet when I replace the named pipe with a regular file, it works fine. The problem is that I have to use a named pipe because this Java code needs to talk to legacy C code through this named pipe, and we unfortunately have no legacy source code, only the executable.
try
{
FileReader frin =
new FileReader( "kbdrespipe");
BufferedReader bin = new BufferedReader( frin );
try
{
outputString = bin.readLine();
}
catch( IOException ioe3 )
{
System.out.println( "Error: " + ioe3 );
}
try
{
frin.close();
}
catch( IOException ioe4 )
{
System.out.println( "Error: " + ioe4 );
}
}
catch( FileNotFoundException fnfe2 )
{
System.out.println( "Error: " + fnfe2 );
}
System.out.println( outputString + "<-DONE" );
Any help would be greatly appreciated.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Interesting. I've never really used named pipes; I only know what I just learned from web searches. A few thoughts:
Try creating new File("kbdrespipe") and evaluating getAbsolutePath(), exists(), isFile() and canRead(). This may give you additional clues. I'm guessing that the named pipe is not being recognized as a "file" at all as far as Java is concerned, but maybe not.
It sounds like on many systems named pipes can only have one reader. (Or if there's more than one reader, their behavior is unspecified as bytes get gobbled by one reader or the other, but not both.) If this is part of a legacy system you're connecting to - is whatever was reading the pipe still active? Can you disable it somehow before starting your own reader?
This may be regarded as a bug in the Solaris JDK. Try searching at the Java Developer Connection here. Right now it seems they've got some sort of error with the bug database; normally it works fine, so I assume it will be back to normal soon. (I reported the error to the webmaster.) Try this when it's up again.
Also try googling for "java solaris named pipe" or something similar. I didn't find an answer there, but I didn't check everything carefully. By omitting "solaris" I found that samba has some classes to do this sort of thing on Windows; maybe this will be instructive.
My best guess though is that you simply can't do this with a FileInputStream or the like, and you'll need to either find a library that does it for Solaris, or write your own in C/C++ and use JNI to connect it to your java program.
Or, maybe you can put together some sort of shell script to read from the named pipe and write the contents to a socket instead. (No idea how to communicate with sockets in Solaris, but I assume it's possible.) Then your Java program can read from the socket instead.
Naturally, suggestions from others here who have worked with named sockets would be welcome. Otherwise, good luck, and please let me know if you find a solution. Cheers...


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading from a Named Pipe File (Solaris 2.6)