I am trying to write a variable to ~/.bash_profile
using commands like echo, but I am unable to write it to the file.
I tried the following,
Runtime run = Runtime.getRuntime();
String line = null;
try {
Process pr = run.exec("echo \"export ANDROID_HOME=/Users/abc/Documents/platform-tool\" >> ~/.bash_profile");
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
while ((line = buf.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
logger.error("Error occurred when getting adb " + e.getMessage());
} catch (InterruptedException ie) {
logger.error("Error occurred when getting adb " + ie.getMessage());
Thread.currentThread().interrupt();
}
I also tried giving ' instead of \" and just echo export still it is not writing to that file. When I try to print the output it prints
"export ANDROID_HOME=/Users/abc/Documents/platform-tool" >> ~/.bash_profile
But the file is empty.
I also tried using printf but that again does not work. Also these commands do work in terminal but using in java, it is not writing to the file.
Any help would be appreciated and if there are other methods than which I'm using please suggest