Add support for environment variables

See gh-12800
This commit is contained in:
Dmytro Nosan
2018-04-09 00:11:27 +03:00
committed by Stephane Nicoll
parent 5dd4a7e91e
commit 95f7e3ca37
14 changed files with 354 additions and 15 deletions

View File

@@ -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 {