title: How do I listen for a response from shell command in android studio?
body: <p>In an android terminal emulator I can type the following commands:</p>
  
  <pre><code>&gt; su
  &gt; echo $(&lt;/sys/class/power_supply/battery/charge_rate)
  </code></pre>
  
  <p>and depending on how the phone is charging the output will be "None", "Normal" or "Turbo". I would like to be able to retrieve this output and store it <strong>as a string value</strong> in my program.</p>
  
  <p>So I've done a little bit of research into this and the code I came up with is as follows:</p>
  
  <pre><code>    String chargeRate = "None";
      try {
          Runtime rt = Runtime.getRuntime();
          Process process = rt.exec("su \"\"echo $(&lt;/sys/class/power_supply/battery/charge_rate)");
  
          BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
  
          if ((chargeRate = stdInput.readLine()) == null)
              chargeRate = "None";
      }
      catch (Exception e) {
          // TODO
      }
  </code></pre>
  
  <p>This is taken from a number of different answers and I'm not quite sure whats wrong with it. I can't step over or past this line while debugging:</p>
  
  <pre><code>if ((chargeRate = stdInput.readLine()) == null)
  </code></pre>
  
  <p>As soon as the debugger reaches this line it says "The application is running"</p>