diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java index e52b4682..c6bff90d 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java @@ -30,11 +30,13 @@ public class BeaconServer { public static Process tryStartCustom() throws Exception { var custom = BeaconConfig.getCustomDaemonCommand(); if (custom != null) { - var command = - ShellTypes.getPlatformDefault().executeCommandWithShell( - custom + (BeaconConfig.getDaemonArguments() != null ? " " + BeaconConfig.getDaemonArguments() : "")); - Process process = Runtime.getRuntime().exec(command); - printDaemonOutput(process, command); + var command = ShellTypes.getPlatformDefault() + .executeCommandListWithShell(custom + + (BeaconConfig.getDaemonArguments() != null + ? " " + BeaconConfig.getDaemonArguments() + : "")); + Process process = Runtime.getRuntime().exec(command.toArray(String[]::new)); + printDaemonOutput(process, ShellTypes.getPlatformDefault().flatten(command)); return process; } return null; @@ -45,7 +47,8 @@ public class BeaconServer { // Tell daemon that we launched from an external tool var command = "\"" + daemonExecutable + "\" --external " + (BeaconConfig.getDaemonArguments() != null ? BeaconConfig.getDaemonArguments() : ""); - Process process = Runtime.getRuntime().exec(ShellTypes.getPlatformDefault().executeCommandWithShell(command)); + Process process = + Runtime.getRuntime().exec(ShellTypes.getPlatformDefault().executeCommandWithShell(command)); printDaemonOutput(process, command); return process; } diff --git a/core/src/main/java/io/xpipe/core/process/ShellType.java b/core/src/main/java/io/xpipe/core/process/ShellType.java index 7d20e3bc..f345ce41 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellType.java +++ b/core/src/main/java/io/xpipe/core/process/ShellType.java @@ -74,6 +74,8 @@ public interface ShellType { String executeCommandWithShell(String cmd); + List executeCommandListWithShell(String cmd); + List createMkdirsCommand(String dirs); String createFileReadCommand(String file); diff --git a/core/src/main/java/io/xpipe/core/process/ShellTypes.java b/core/src/main/java/io/xpipe/core/process/ShellTypes.java index 31201e9b..7db71a10 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellTypes.java +++ b/core/src/main/java/io/xpipe/core/process/ShellTypes.java @@ -140,6 +140,11 @@ public class ShellTypes { return "cmd.exe /C " + cmd + ""; } + @Override + public List executeCommandListWithShell(String cmd) { + return List.of("cmd", "/C", cmd); + } + @Override public List createMkdirsCommand(String dirs) { return List.of("(", "if", "not", "exist", dirs, "mkdir", dirs, ")"); @@ -232,6 +237,11 @@ public class ShellTypes { return "$env:" + variableName + " = \"" + escapeStringValue(value) + "\""; } + @Override + public List executeCommandListWithShell(String cmd) { + return List.of("powershell", "-Command", cmd); + } + @Override public String queryShellProcessId(ShellProcessControl control) throws IOException { control.writeLine("echo $PID"); @@ -387,6 +397,11 @@ public class ShellTypes { public abstract static class PosixBase implements ShellType { + @Override + public List executeCommandListWithShell(String cmd) { + return List.of(getExecutable(), "-c", cmd); + } + public String getScriptEchoCommand(String s) { return "#!" + getExecutable() + "\n" + getEchoCommand(s, false) + "\nrm -- \"$0\""; }