Is there a way in Java to get an environment variable from a remote server?
I am currently executing:
Runtime.getRuntime().exec(new String[] {
"ssh", "myuser@myserver", "source myenvfile; echo $MY_VAR"
});
But it returns blank (although my variable should contain something).
I get a result for commands such as df but none for echo. Can someone tell me what am I doing wrong?
EDIT : Does anyone have a better solution that this to do so ?
NB: I want to avoid the use of a SSH library.
Thank you in advance for helping me.
There is actually a better solution: using a ProcessBuilder.
Runtime.getRuntime().exec()has quite a few problems which make it not really suitable for process execution.