What I would like my code to achieve is calling one of the available two shell scripts and execute some commands whose output will be printed in a .txt file.
So far I have managed to achieve this (by calling the first script) but when I try to call the second script the terminal is not opening and the output of the commands is not appended to the .txt file.
My code is as follows:
File file = new File("res/script1.sh");
String absolutePath = file.getAbsolutePath();
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("open -a Terminal "+absolutePath);
After this execution the .txt file contains the phrase "Hello World".
My first try was to just change /script1.sh to /script2.sh as I thought the second one would append another "Hellow World" in a second line of the .txt file. This is not working as the contents of the file remain the same and the terminal is not even opening as opposed to the first case.
I have also tried to duplicate the code for the two scripts and to execute one or the other based on an input value i==1 or i==2 but with no luck.
Any thoughts why I cannot make the second script work even though it is identical to the first?
My script's code
#!/bin/sh
cd "$(dirname "$0")"
echo Hello World >> output.txt
exit