I am trying to run some LINUX like commands from an android application, I want my application to run some custom commands like pkg
, dpkg
etc. basically I need my application to act as a terminal app, for this, I created a Linux file structure with necessary libraries and binaries inside the application package, i.e. I placed my files under the /data/data/com.example.root.app/files/usr/bin
directory structure. Then I am executing them from my code:
Process process;
try {
process = Runtime.getRuntime().exec(new String[]{"pkg","search","apache2"}, env, new File(cwd));
} catch (IOException e) {
// TODO: Visible error message?
}
I am using variable env to set the environment variables PATH, LD_LIBRARY_PATH, HOME etc.. which I am passing to the process above. also, i start the process from the directory which contains the commands i.e
String cwd = "/data/data/com.example.root.app/files/usr/bin"
I am able to run rudimentary commands like env
, ls -l
, pwd
but I am not able to run the custom-built commands like pkg
.
when I try to execute the command pkg
it throws IOException error =13 permission denied
please be informed that I have set the executable permissions to 777 recursively to the whole directory, just to find whether it runs, but it doesn't.
Also when I use already existing terminal application there I am able to run the pkg
command