title: How to pipe input to Java program with bash
body: <p>My Java program is listening on standard input:</p>
  
  <pre><code>InputStreamReader isReader = new InputStreamReader(System.in);
  BufferedReader bufReader = new BufferedReader(isReader);
  while(true){
      try {
          String inputStr = null;
          if((inputStr=bufReader.readLine()) != null) {
              ...
          }
          else {
              System.out.println("inputStr is null");
          }
      }
      catch (Exception e) {
          ...
      }
  }
  </code></pre>
  
  <p>Now, I want to pipe input to this program from bash. I tried the following:</p>
  
  <pre><code>echo "hi" | java -classpath ../src test.TestProgram
  </code></pre>
  
  <p>But it's just printing <code>inputStr is null</code> infinite times. What am I doing wrong?</p>
  
  <p>Edit 1: Updated question to include more code / context.</p>
  
  <hr>
  
  <p>Edit 2:</p>
  
  <p>Looks like I'm experiencing the same issue as this OP: <a href="https://stackoverflow.com/questions/1431551/command-line-pipe-input-in-java">Command Line Pipe Input in Java</a></p>
  
  <p>How can I fix the program so that I can pipe input in for testing, but running the program normally will allow users to enter input on standard input as well?</p>