I need to execute multiple system (linux) commands from Java code in the way that they are executed from the same “session”.
Example would be first execute:
cd /home
And after that another command would be executed from /home directory (commands I will be executing are far more complex then this example, I know this example is not perfect because this can be done with ProcessBuilder and setting the home directory, but this is not my case)
My current way of executing commands in java is:
Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", "COMMAND_HERE"})
And then I read the output from the java.lang.Process which is the return value of the method above.
To sum it up, I need a way to execute multiple commands from the same session + read the output of them.