1

On android there are two methods to run shell commands either using java or using jni.

I was wondering if it is more efficient to run shell commands on one or the other.

Java

runtime.exec("su");

Jni

system("su");

Though I did hear that Jni doesn't accept multiple commands which might be a setback.

2 Answers2

2

The mechanism under the Runtime.exec() is fork/exec in native which is a more common and safe way to execute a command.

system() in jni use your current shell to interpret the command.

Moreover, you can use fork/exec in jni to execute command.

For the comparison of these two ways, see here.

Finally, it's hard to say which one is more efficient, both of them have to create a new process to handle the execution.

Community
  • 1
  • 1
alijandro
  • 11,627
  • 2
  • 58
  • 74
0

You can also try with using http://alvinalexander.com/java/java-exec-processbuilder-process-1 .

I hope so that will be helpfull for you ;)

pkruk
  • 809
  • 1
  • 7
  • 24