I have a java class that runs any scripts on my server i require, and it works nicely.
I have an issue however, i need to run one script from a specific location and not sure how to do that. Is there a way to 'cd' to a directory before running my script in my java method?
My current method:
public String runScriptFile(String pathname) throws IOException{
Runtime rt = Runtime.getRuntime();
String output="";
Process proc = rt.exec(pathname);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(proc.getErrorStream()));
String s = null;
while ((s = stdInput.readLine()) != null) {
output+=s;
}
while ((s = stdError.readLine()) != null) {
output+=s;
}
return output;
}