title: How to execute shell command from android app?
body: <p>I want to execute android shell command from my android app to execute a uiautomator test jar.</p>
  
  <p>i have tried following options. but neither of them is working for me...</p>
  
  <pre><code> public void execute(String shellcommand) {
          Runtime rt = Runtime.getRuntime();
          Process p = r.exec(new String[]{"/system/bin/sh", "-c", shellcommand});
   }
  </code></pre>
  
  <p>Also tried...</p>
  
  <pre><code>public void execute(String shellcommand) {
      Process su = Runtime.getRuntime().exec("su");
      DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
  
      outputStream.writeBytes(shellcommand + "\n");
      outputStream.flush();
  
      outputStream.writeBytes("exit\n");
      outputStream.flush();
      su.waitFor();
  }
  </code></pre>
  
  <p>Please tell what mistake i m doing?</p>