I am trying to run a UNIX ssh command from a Java application, which needs to be run by a specific username or it won't have the correct permissions to execute. The application runs under a different username. I have tried setting the env. variables for LOGNAME and USER and USERNAME to the one I want, then executing the command like this:
String [] envVarsList = new String[3];
envVarsList[0] = "USER=wkadmin";
envVarsList[1] = "LOGNAME=wkadmin";
envVarsList[2] = "USERNAME=wkadmin";
proc = rt.exec("/usr/local/bin/ssh -2 serverName -l wkadmin -n tail /path/filename", envVarsList);
int exitVal = proc.waitFor();
log.info("ExitValue of runtime process = " + exitVal);
It returns a value of 255.
The command works fine when I run it outside the Java program, so I know it will work if I just can get the env. variables right. Is this possible to do with Runtime.exec?
String [] envVarsList = new String[3];
envVarsList[0] = "USER=wkadmin";
envVarsList[1] = "LOGNAME=wkadmin";
envVarsList[2] = "USERNAME=wkadmin";
proc = rt.exec("/usr/local/bin/ssh -2 serverName -l wkadmin -n tail /path/filename", envVarsList);
int exitVal = proc.waitFor();
log.info("ExitValue of runtime process = " + exitVal);
It returns a value of 255.
The command works fine when I run it outside the Java program, so I know it will work if I just can get the env. variables right. Is this possible to do with Runtime.exec?