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"));
|
private static final ScheduledExecutorService s_executors = Executors.newScheduledThreadPool(10, new NamedThreadFactory("Script"));
|
||||||
|
|
||||||
|
String _workDir;
|
||||||
ArrayList<String> _command;
|
ArrayList<String> _command;
|
||||||
long _timeout;
|
long _timeout;
|
||||||
Process _process;
|
Process _process;
|
||||||
@ -106,6 +107,10 @@ public class Script implements Callable<String> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWorkDir(String workDir) {
|
||||||
|
_workDir = workDir;
|
||||||
|
}
|
||||||
|
|
||||||
protected String buildCommandLine(String[] command) {
|
protected String buildCommandLine(String[] command) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
boolean obscureParam = false;
|
boolean obscureParam = false;
|
||||||
@ -159,6 +164,9 @@ public class Script implements Callable<String> {
|
|||||||
try {
|
try {
|
||||||
ProcessBuilder pb = new ProcessBuilder(command);
|
ProcessBuilder pb = new ProcessBuilder(command);
|
||||||
pb.redirectErrorStream(true);
|
pb.redirectErrorStream(true);
|
||||||
|
if(_workDir != null)
|
||||||
|
pb.directory(new File(_workDir));
|
||||||
|
|
||||||
_process = pb.start();
|
_process = pb.start();
|
||||||
if (_process == null) {
|
if (_process == null) {
|
||||||
_logger.warn("Unable to execute: " + buildCommandLine(command));
|
_logger.warn("Unable to execute: " + buildCommandLine(command));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user