Run powershell -Command instead of cmd /c

This commit is contained in:
Reinhard Pointner 2017-02-06 01:09:19 +08:00
parent ddf40be144
commit c701a20bbf
1 changed files with 3 additions and 3 deletions

View File

@ -289,17 +289,17 @@ public abstract class ScriptShellBaseClass extends Script {
} }
public int execute(Object... args) throws Exception { public int execute(Object... args) throws Exception {
Stream<String> cmd = stream(args).map(Objects::toString); Stream<String> cmd = stream(args).filter(Objects::nonNull).map(Objects::toString);
if (Platform.isWindows()) { if (Platform.isWindows()) {
// normalize file separator for windows and run with powershell so any executable in PATH will just work // normalize file separator for windows and run with powershell so any executable in PATH will just work
cmd = Stream.concat(Stream.of("powershell", "-Command"), cmd); cmd = Stream.concat(Stream.of("powershell", "-NonInteractive", "-NoProfile", "-NoLogo", "-ExecutionPolicy", "Bypass", "-Command"), cmd);
} else if (args.length == 1) { } else if (args.length == 1) {
// make Unix shell parse arguments // make Unix shell parse arguments
cmd = Stream.concat(Stream.of("sh", "-c"), cmd); cmd = Stream.concat(Stream.of("sh", "-c"), cmd);
} }
ProcessBuilder process = new ProcessBuilder(cmd.toArray(String[]::new)).inheritIO(); ProcessBuilder process = new ProcessBuilder(cmd.collect(toList())).inheritIO();
return process.start().waitFor(); return process.start().waitFor();
} }