title: IOException at InputStreamReader
body: <p>making a class , with several functions , I am having a problem with one of these functions which will use the ProcessBuilder to send a command and take its output as a string , acting as a shell command . When I use it , it catches an IOException , with a Bad file number , at the InputStreamReader , and returns "ERROR!!!" , here is my code , if you need to know anything about this comment ... I am using the command "ls" btw , "ls /sdcard/" ...</p>
  
  <pre><code>     public String builder(String str) {    
      startTimer(); // A method that gets the current time as int
      String[] array = str.split(" " , 2);
      String cmd = array[0] + " " + array[1];
      System.out.println("\nexecuting: " + cmd + "----");
      String AllText = "";
      try {
          String anyString;
          //Process process = new ProcessBuilder("sh","-c","\"",cmd,"\"").start();
          Process process = new ProcessBuilder(array).start();
  
          BufferedReader OUT = new BufferedReader(new InputStreamReader(process.getInputStream())); // Here is My error
          BufferedReader ERR = new BufferedReader(new InputStreamReader(process.getErrorStream()));
          try {
              for (int x = endTimer()/* a method which subtracts the startTimer() from current time to get the time passed */ ; endTimer()&lt;= 5000 ; x++){
                  process.waitFor();
              }process.destroy();
  
          } catch (InterruptedException ex) {
              ex.printStackTrace();
          }
          while ((anyString = ERR.readLine()) != null) {
              AllText = AllText + "\n" + anyString;
          }
          while ((anyString = OUT.readLine()) != null) {
              AllText = AllText + "\n" + anyString;
              while ((anyString = ERR.readLine()) != null) {
                  AllText = AllText + "\n" + anyString;
              }
          }
  
          return AllText;
      } catch (Exception ex) {
          ex.printStackTrace();
          return "ERROR!!!";
  
      }
  </code></pre>
  
  <p>Here is the Stack Trace when pressing the button :</p>
  
  <pre><code>12-03 18:55:36.475: W/System.err(17973): java.io.IOException: read failed: EBADF (Bad file number)
  12-03 18:55:36.507: W/System.err(17973):    at libcore.io.IoBridge.read(IoBridge.java:442)
  12-03 18:55:36.507: W/System.err(17973):    at java.io.FileInputStream.read(FileInputStream.java:179)
  12-03 18:55:36.507: W/System.err(17973):    at java.io.InputStreamReader.read(InputStreamReader.java:244)
  12-03 18:55:36.507: W/System.err(17973):    at java.io.BufferedReader.fillBuf(BufferedReader.java:130)
  12-03 18:55:36.507: W/System.err(17973):    at java.io.BufferedReader.readLine(BufferedReader.java:354)
  12-03 18:55:36.507: W/System.err(17973):    at com.example.activity.over.other.Shells.builder(Shells.java:542)
  12-03 18:55:36.507: W/System.err(17973):    at com.example.activity.over.other.MainActivity$2.onClick(MainActivity.java:91)
  12-03 18:55:36.514: W/System.err(17973):    at android.view.View.performClick(View.java:4202)
  12-03 18:55:36.514: W/System.err(17973):    at android.view.View$PerformClick.run(View.java:17340)
  12-03 18:55:36.514: W/System.err(17973):    at android.os.Handler.handleCallback(Handler.java:725)
  12-03 18:55:36.514: W/System.err(17973):    at android.os.Handler.dispatchMessage(Handler.java:92)
  12-03 18:55:36.514: W/System.err(17973):    at android.os.Looper.loop(Looper.java:137)
  12-03 18:55:36.514: W/System.err(17973):    at android.app.ActivityThread.main(ActivityThread.java:5039)
  12-03 18:55:36.514: W/System.err(17973):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-03 18:55:36.522: W/System.err(17973):    at java.lang.reflect.Method.invoke(Method.java:511)
  12-03 18:55:36.522: W/System.err(17973):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  12-03 18:55:36.522: W/System.err(17973):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  12-03 18:55:36.522: W/System.err(17973):    at dalvik.system.NativeStart.main(Native Method)
  12-03 18:55:36.522: W/System.err(17973): Caused by: libcore.io.ErrnoException: read failed: EBADF (Bad file number)
  12-03 18:55:36.530: W/System.err(17973):    at libcore.io.Posix.readBytes(Native Method)
  12-03 18:55:36.530: W/System.err(17973):    at libcore.io.Posix.read(Posix.java:123)
  12-03 18:55:36.530: W/System.err(17973):    at libcore.io.BlockGuardOs.read(BlockGuardOs.java:149)
  12-03 18:55:36.530: W/System.err(17973):    at libcore.io.IoBridge.read(IoBridge.java:432)
  12-03 18:55:36.530: W/System.err(17973):    ... 17 more
  </code></pre>