title: Creating named pipes in Java
body: <p>I am experimenting with creating named pipes using Java. I am using Linux. However, I am running into a problem where writing to the pipe hangs.</p>
  
  <pre><code>    File fifo = fifoCreator.createFifoPipe("fifo");
      String[] command = new String[] {"cat", fifo.getAbsolutePath()};
      process = Runtime.getRuntime().exec(command);
  
      FileWriter fw = new FileWriter(fifo.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);
      bw.write(boxString); //hangs here
      bw.close();
      process.waitFor();
      fifoCreator.removeFifoPipe(fifo.toString());
  </code></pre>
  
  <p>fifoCreator:</p>
  
  <pre><code>@Override
  public File createFifoPipe(String fifoName) throws IOException, InterruptedException {
      Path fifoPath = propertiesManager.getTmpFilePath(fifoName);
      Process process = null;
      String[] command = new String[] {"mkfifo", fifoPath.toString()};
      process = Runtime.getRuntime().exec(command);
      process.waitFor();
      return new File(fifoPath.toString());
  }
  
  @Override
  public File getFifoPipe(String fifoName) {
      Path fifoPath = propertiesManager.getTmpFilePath(fifoName);
      return new File(fifoPath.toString());
  }
  
  @Override
  public void removeFifoPipe(String fifoName) throws IOException {
      Files.delete(propertiesManager.getTmpFilePath(fifoName));
  }
  </code></pre>
  
  <p>I am writing a string that consists of 1000 lines. Writing 100 lines work but 1000 lines doesn't.</p>
  
  <p>However, if I run "cat fifo" on an external shell, then the program proceeds and writes everything out without hanging. Its strange how the cat subprocess launched by this program doesn't work.</p>
  
  <p>EDIT: I did a ps on the subprocess and it has the status "S". </p>