title: Why does the output of my shell script doesn't print in console?
body: <p>I am trying to print the output of a shell script on the console using java. When I manually run the script, I get</p>
  
  <pre><code>C:/Users/user1/Desktop/shell.sh: line 78: /usr/ucb/ps: No such file or directory
  &lt;STATUS&gt;: Probe [ devicename ] is not running!
  </code></pre>
  
  <p>But, when I try to run it on my Java program, the output is not being printed on the console.
  My code is:</p>
  
  <pre><code>ProcessBuilder processBuilder = new ProcessBuilder("C:/Program Files/Git/git-bash.exe","C:/Users/user1/Desktop/shell.sh");
  
  try {
  
      Process process = processBuilder.start();
  
      StringBuilder output = new StringBuilder();
  
      BufferedReader reader = new BufferedReader(
              new InputStreamReader(process.getInputStream()));
  
      String line;
      while ((line = reader.readLine()) != null) {
          output.append(line + "\n");
          System.out.println(line);
      }
  
      int exitVal = process.waitFor();
      if (exitVal == 0) {
          System.out.println("Success!");
          System.out.println(output);
          System.exit(0);
      } else {
          //abnormal...
      }
  
  } catch (IOException e) {
      e.printStackTrace();
  } catch (InterruptedException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>The only output I am getting is "Success". When I debugged my code, I found that the code never enters the condition </p>
  
  <pre><code>while ((line = reader.readLine()) != null)
  </code></pre>
  
  <p>even though, in the bash terminal, there are lines of output. Why is this happening?</p>
  
  <p>I am stuck at this point and I couldn't find any other explanations for this problem. Kindly help.</p>