From 19224b06b8f2cb1b8baeaf7e8bdfa77ab267dd45 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam Date: Thu, 14 Mar 2019 09:42:54 +0800 Subject: Fix process runner on unix Issue-ID: CLI-129 Change-Id: Ic40c94b1059453858ff36e302beb44dbb4c1613b Signed-off-by: Kanagaraj Manickam k00365106 --- .../src/main/java/org/onap/cli/fw/utils/ProcessRunner.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'framework/src') diff --git a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java index 9b896230..eb335837 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java @@ -28,10 +28,14 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import org.apache.commons.io.IOUtils; +import org.onap.cli.fw.cmd.OnapCommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ProcessRunner { + private static Logger log = LoggerFactory.getLogger(ProcessRunner.class); public static final String WIN_SHELL = "cmd.exe /c "; - public static final String UNIX_SHELL = "sh -c "; + public static final String UNIX_SHELL = ""; private String []cmd = null; private String shell = System.getProperty("os.name").toLowerCase().startsWith("windows") ? WIN_SHELL : UNIX_SHELL; private String cwd = System.getProperty("user.home"); @@ -80,6 +84,7 @@ public class ProcessRunner { Process p = null; final StringWriter writerOutput = new StringWriter(); final StringWriter writerError = new StringWriter(); + if (this.cmd.length == 1) { p = Runtime.getRuntime().exec(this.shell + this.cmd[0], this.env, null); } else { @@ -113,6 +118,9 @@ public class ProcessRunner { this.exitCode = p.exitValue(); this.output = writerOutput.toString(); this.error = writerError.toString(); + log.debug("CMD: " + Arrays.asList(this.cmd).toString() + "\nWORKING_DIR: " + this.cwd + "\nENV: " + + ((this.env == null) ? this.env : Arrays.asList(this.env).toString()) + + "\nOUTPUT: " + this.output + "\nERROR: " + this.error + "\nEXIT_CODE: " + this.exitCode); p.destroy(); } -- cgit 1.2.3-korg