proc = Runtime.getRuntime().exec(new String[]{"ls"}); 

Using the code above, you can run ls, you can also start the process with arguments. But how to run something like this?

 ls | egrep "init|sys" 

This is clearly not going to work:

 proc = Runtime.getRuntime().exec(new String[]{"ls","|","egrep","\"init|sys\""}); 
  • On a large SO, it is recommended to draw all the commands into a single-line script, and run it as a parameter for sh -c . - zRrr
  • I tried. Error running exec (). Command: [/ bin / sh, -c, logcat | grep something] Working Directory: null Environment: null - user64675

0