From 7e48db22be2cff0a69943f27c7419f64de89c413 Mon Sep 17 00:00:00 2001 From: steph-roy Date: Tue, 23 Jan 2018 17:05:54 -0500 Subject: [PATCH] Added new config option to override name of PowerShell executable In PowerShell 6, some unix distros have changed the name of the executable from 'powershell' to 'pwsh'. --- src/main/java/com/profesorfalken/jpowershell/PowerShell.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/profesorfalken/jpowershell/PowerShell.java b/src/main/java/com/profesorfalken/jpowershell/PowerShell.java index 2e7e039..885c591 100644 --- a/src/main/java/com/profesorfalken/jpowershell/PowerShell.java +++ b/src/main/java/com/profesorfalken/jpowershell/PowerShell.java @@ -64,6 +64,7 @@ public class PowerShell { private int waitPause = 10; private long maxWait = 10000; private boolean remoteMode = false; + private String unixCmdName = "powershell"; // Variables for script mode private boolean scriptMode = false; @@ -105,6 +106,8 @@ public PowerShell configuration(Map config) { this.remoteMode = Boolean .valueOf((config != null && config.get("remoteMode") != null) ? config.get("remoteMode") : PowerShellConfig.getConfig().getProperty("remoteMode")); + this.unixCmdName = (config != null && config.get("unixCmdName") != null) ? config.get("unixCmdName") + : PowerShellConfig.getConfig().getProperty("unixCmdName"); } catch (NumberFormatException nfe) { Logger.getLogger(PowerShell.class.getName()).log(Level.SEVERE, "Could not read configuration. Use default values.", nfe); @@ -121,7 +124,7 @@ private PowerShell initalize() throws PowerShellNotAvailableException { pb = new ProcessBuilder("cmd.exe", "/c", "chcp", codePage, ">", "NUL", "&", "powershell.exe", "-ExecutionPolicy", "Bypass", "-NoExit", "-Command", "-"); } else { - pb = new ProcessBuilder("powershell -nologo -noexit -Command -"); + pb = new ProcessBuilder(unixCmdName, "-nologo", "-noexit", "-Command", "-"); } try {