Using Fedora 12: mkfifo pipe creates a pipe.
When I use the following code to try to open an input stream against the named pipe it blocks on the FileInputStream constructor unless I create a writer to the pipe, such as opening another terminal and running:
tee pipe
public static void main(String[] args){
try {
File pipe = new File("/tmp/pipes_debugging/pipeToJava");
System.out.println( pipe.canRead() );
FileInputStream fis = new FileInputStream(pipe);
System.out.println("exiting.");
} catch (Exception e) {
e.printStackTrace();
}
}
Output:
true
<blocks - thread trace shown below>
Thread [main] (Suspended)
FileInputStream.open(String) line: not available [native method]
FileInputStream.<init>(File) line: 137
PipesDebugging.main(String[]) line: 12
Copied from comments:
It seems like a correct behavior. What are you trying to do? – Banthar Jun 20 at 7:42
Yep, I think this thread might just have answered my question: stackoverflow.com/questions/2246862/… – I’m trying to read from the pipe, I was expecting the stream to open and block on read(), not block on opening the stream. – David Parks Jun 20 at 7:52