Add support for environment variables
See gh-12800
This commit is contained in:
committed by
Stephane Nicoll
parent
5dd4a7e91e
commit
95f7e3ca37
@@ -20,6 +20,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Utility used to run a process.
|
||||
@@ -28,6 +30,7 @@ import java.util.Collection;
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
* @author Dmytro Nosan
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public class RunProcess {
|
||||
@@ -63,14 +66,19 @@ public class RunProcess {
|
||||
}
|
||||
|
||||
public int run(boolean waitForProcess, String... args) throws IOException {
|
||||
return run(waitForProcess, Arrays.asList(args));
|
||||
return run(waitForProcess, Arrays.asList(args), Collections.emptyMap());
|
||||
}
|
||||
|
||||
protected int run(boolean waitForProcess, Collection<String> args)
|
||||
public int run(boolean waitForProcess, String[] args, Map<String, String> environmentVariables) throws IOException {
|
||||
return run(waitForProcess, Arrays.asList(args), environmentVariables);
|
||||
}
|
||||
|
||||
protected int run(boolean waitForProcess, Collection<String> args, Map<String, String> environmentVariables)
|
||||
throws IOException {
|
||||
ProcessBuilder builder = new ProcessBuilder(this.command);
|
||||
builder.directory(this.workingDirectory);
|
||||
builder.command().addAll(args);
|
||||
builder.environment().putAll(environmentVariables);
|
||||
builder.redirectErrorStream(true);
|
||||
builder.inheritIO();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user