mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Allow Script to execute under a specified working directory
This commit is contained in:
parent
4534299092
commit
e12f9ad19d
@ -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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user