I just want to execute my file from a specific folder. in my case /data/data/my-package/files/.
So i tried :
Process process2=Runtime.getRuntime().exec("cd /data/data/my-package/files/");
process2.waitFor();
process2=Runtime.getRuntime().exec("./myfile");
It doesn’t work. could anyone tell me please the right way to do that . Thanks
It should be possible to call the executable with a specific working directory using
Runtime.exec(String command, String[] envp, File dir)as follows:
maybe without the full path to
myfileContext#getFilesDir()instead of hardcoding the path should work too and is safer / cleaner than specifying the path yourself since it is not guaranteed that/data/data/..is always the correct path for all devices.
The problem with
cd somewhereis that the directory is changed for a different Process so the second call toexecin a new Process does not see the change.