Allow Script to execute under a specified working directory

This commit is contained in:
Kelven Yang 2010-09-10 16:47:00 -07:00 committed by edison
parent 4534299092
commit e12f9ad19d

View File

@ -52,6 +52,7 @@ public class Script implements Callable<String> {
private static final ScheduledExecutorService s_executors = Executors.newScheduledThreadPool(10, new NamedThreadFactory("Script"));
String _workDir;
ArrayList<String> _command;
long _timeout;
Process _process;
@ -105,6 +106,10 @@ public class Script implements Callable<String> {
_command.add(value);
return this;
}
public void setWorkDir(String workDir) {
_workDir = workDir;
}
protected String buildCommandLine(String[] command) {
StringBuilder builder = new StringBuilder();
@ -159,6 +164,9 @@ public class Script implements Callable<String> {
try {
ProcessBuilder pb = new ProcessBuilder(command);
pb.redirectErrorStream(true);
if(_workDir != null)
pb.directory(new File(_workDir));
_process = pb.start();
if (_process == null) {
_logger.warn("Unable to execute: " + buildCommandLine(command));