is this the right approach?
public void doSomething()
{
Process p;
String[] cmd = {"/usr/bin/ssh", "someRemoteMachine", "/absPathToMyProg/myProg"};
String[] envp = {"PATH=path_needed_toRun_myProg"};
try
{
p = Runtime.getRuntime().exec(cmd,envp);
}
catch (IOException e)
{
System.err.println("Epic Fail");
}
}
Apart from using JSch (or any other Java SSH implementation), like Suraj said, passing the Path via environment variables is likely not to work, since most SSH deamons only accept a small set of variables from the other side (mostly related to localization or terminal type).
As the argument to
ssh(or the “command”, if using JSch with an ChannelExec) is passed to the remote shell for execution, you could try to define the path in this command (if your default shell is something compatible to the POSIXsh):Your array for Runtime.exex thus would look like this: