Reputation: 1411
Is there any advantage/disadvantage of executing a linux command in an android app rather than using the java alternative?
ex:
File file = new File("file.txt");
file.delete();
vs
rm file.txt
Upvotes: 1
Views: 149
Reputation: 22663
None, really, or at least not in the general case.
I could see it as being useful if you want to invoke a separate and complex program that doesn't expose a programmatic interface. However in that case I'd still go with invoking via ProcessBuilder
rather than using a system execution.
unsafe
If it's not your program, you don't know what it does. It may be tampered with, and it may require using different permissions and privileges.
unstable
If it's not your program, you don't really know if it's there and if it always will be.
wasteful
It spawns an extra process for no good reason.
opaque
It's harder for you to monitor a long-running task and to check for return codes (and again the conventions for these may change in the future, which brings us back to unsafe and unstable).
Upvotes: 4