title: Error while executing adb command programmatically
body: <p>I am trying to execute adb commands programmatically</p>
  
  <p>Here is my code:</p>
  
  <pre><code>File f = new File(Environment.getExternalStorageDirectory(), "screen" + System.currentTimeMillis() + ".png");
  
  new ExecuteCommand(MainActivity.this).execute("adb shell screencap -p "
          + Environment.getExternalStorageDirectory().getPath() +
          "/" + "screen" + System.currentTimeMillis() + ".png");
  </code></pre>
  
  <p>ExecuteCommand Class:</p>
  
  <pre><code>public class ExecuteCommand extends AsyncTask&lt;String, String, String&gt; {
  
      Context mContext=null;
      public ExecuteCommand(Context _ctx)
      {
          mContext =_ctx;
      }
  
      ProgressDialog progressdailog;
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          progressdailog = ProgressDialog.show(mContext,
                  "Executing", "Please Wait");
      }
      @Override
      protected String doInBackground(String... params) {
          Process p;
          StringBuffer output = new StringBuffer();
          try {
              p = Runtime.getRuntime().exec(params[0]);
              BufferedReader reader = new BufferedReader(
                      new InputStreamReader(p.getInputStream()));
              String line = "";
              while ((line = reader.readLine()) != null) {
                  output.append(line + "\n");
                  p.waitFor();
              }
          } catch (IOException e) {
              e.printStackTrace();
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          String response = output.toString();
          return response;
      }
  
      @Override
      protected void onPostExecute(String result) {
          super.onPostExecute(result);
          progressdailog.dismiss();
          Log.e("Output", result);
      }
  }
  </code></pre>
  
  <p>Problem in logs: </p>
  
  <blockquote>
    <p>07-31 15:26:31.832  18716-18716/com.example E/Output﹕ cannot bind 'tcp:5038' * daemon not running. starting it now on port 5038 *</p>
  </blockquote>
  
  <p>I am not able to take a screenshot, but if I ran the same command on command prompt then this is working fine. </p>
  
  <p>But if I execute </p>
  
  <pre><code>new ExecuteCommand(MainActivity.this).execute("ls");
  </code></pre>
  
  <p>this works fine. Where is the problem in command?</p>