title: On Android, unable to run procrank from java app
body: <p>I would like to have an app (service) that runs in the background, running procrank on a timer &amp; writing the output to a file on the sdcard. Essentially I want to execute "/system/xbin/procrank > /sdcard/procrank.txt". During the wait time I do some [minimal] processing of the file, so I can overwrite it the next time it runs.</p>
  
  <p>This is on a test phone, so it can be considered as "rooted". I have tried many different ways to run the command without success. </p>
  
  <p>When I use this:</p>
  
  <pre><code>        String[] cmd = { "/system/xbin/procrank &gt; /sdcard/procrank_result.txt" };
          Process process = new ProcessBuilder()
          .command(cmd)
          .redirectErrorStream(true)
          .start();
              BufferedReader in = new BufferedReader(
                      new InputStreamReader(process.getInputStream()));
              String line = "";
              while ((line = in.readLine()) != null) {
                  Log.i(Constants.TAG, "Line=" + line);
              }
          process.waitFor();
  </code></pre>
  
  <p>I get an IOException:</p>
  
  <pre><code>09-28 02:48:16.307: W/System.err(9579): java.io.IOException: Error running exec(). Command: [/system/xbin/procrank &gt; /sdcard/procrank_result.txt] Working Directory: null Environment: [ANDROID_ROOT=/system, EMULATED_STORAGE_SOURCE=/mnt/shell/emulated, LOOP_MOUNTPOINT=/mnt/obb, ...
  </code></pre>
  
  <p>So I thought I would just issue the command and read the output:</p>
  
  <pre><code>        String[] cmd = { "/system/xbin/procrank" };
          Process process = new ProcessBuilder()
          .command(cmd)
          .redirectErrorStream(true)
          .start();
              BufferedReader in = new BufferedReader(
                      new InputStreamReader(process.getInputStream()));
              String line = "";
              while ((line = in.readLine()) != null) {
                  Log.i(Constants.TAG, "Line=" + line);
              }
          process.waitFor();
  </code></pre>
  
  <p>but I get an error from procrank that I don't understand:</p>
  
  <pre><code>Line=Error creating kernel interface -- does this kernel have pagemap?
  </code></pre>
  
  <p>Can anyone help me with this?</p>
  
  <p>Also, I have tried many different ways to issue the command, so another variation of using process from getRuntime().exec probably won't work unless it's different from the many other solutions here on StackOverflow.</p>
  
  <p>Yes, my sdcard is writable and /sdcard is equivalent to . I can issue the command from adb shell and it creates the file.</p>
  
  <p>Would I have more luck with trying to connect via socket to localhost and then issuing the command? </p>