diff options
author | Murali-P <murali.p@huawei.com> | 2017-04-21 18:36:41 +0530 |
---|---|---|
committer | Murali-P <murali.p@huawei.com> | 2017-04-21 18:36:41 +0530 |
commit | ee2e1f33b8c7222f7ed329b37e35240e196e0f4e (patch) | |
tree | ec76965e786c6275918f74febd93eaab2110ad0e /vnf-sdk-function-test | |
parent | a61904b7b8fc0e3691147cf710cc6a4bb6181795 (diff) |
Runtime.exec fails in linux
Resolved:VNFSDK-21
VNF SDK function test
Change-Id: If356d8b15c6d547f439ced92454a7067d98aaff5
Signed-off-by: Murali-P <murali.p@huawei.com>
Diffstat (limited to 'vnf-sdk-function-test')
2 files changed, 43 insertions, 26 deletions
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java index 57e4baf..4b6c33d 100644 --- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java +++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java @@ -86,20 +86,17 @@ public class TaskExecution { String argumentFilePath = confDir + "config.args "; String robotScript = confDir + "RemoteConnection.robot"; - String shellcommand = ApplicationConstants.SHELL_COMMAND; - if(SystemUtils.IS_OS_LINUX) { - shellcommand = ApplicationConstants.SHELL_COMMAND_BASH; - } - Process process = null; InputStream inputStream = null; int ch; try { - String command = - shellcommand + "robot --argumentfile " + argumentFilePath + robotvariables + " " + robotScript; + String command = "robot --argumentfile " + argumentFilePath + robotvariables + " " + robotScript; LOGGER.info("Command execute to execute the script:" + command); - process = Runtime.getRuntime().exec(command); - inputStream = process.getInputStream(); + process = Runtime.getRuntime().exec(new String[] {getShellCommand(), getShellArg(), command}); + if(process != null) { + process.waitFor(); + inputStream = process.getInputStream(); + } while((ch = inputStream.read()) != -1) { LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch)); } @@ -153,18 +150,19 @@ public class TaskExecution { // Execute script directory String robotScript = confDir + "execute.robot"; - String shellcommand = ApplicationConstants.SHELL_COMMAND; - if(SystemUtils.IS_OS_LINUX) { - shellcommand = ApplicationConstants.SHELL_COMMAND_BASH; - } + Process process = null; InputStream inputStream = null; int ch; try { - String command = shellcommand + ApplicationConstants.ROBOT + remoteArgs + robotScript; + String command = ApplicationConstants.ROBOT + remoteArgs + robotScript; LOGGER.info("Command execute to execute the script:" + command); - process = Runtime.getRuntime().exec(command); - inputStream = process.getInputStream(); + process = Runtime.getRuntime().exec(new String[] {getShellCommand(), getShellArg(), command}); + if(process != null) { + process.waitFor(); + inputStream = process.getInputStream(); + } + while((ch = inputStream.read()) != -1) { LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch)); } @@ -218,19 +216,18 @@ public class TaskExecution { // Execute the command String robotScript = confDir + "upload.robot"; - String shellcommand = ApplicationConstants.SHELL_COMMAND; - if(SystemUtils.IS_OS_LINUX) { - shellcommand = ApplicationConstants.SHELL_COMMAND_BASH; - } - Process process = null; InputStream inputStream = null; int ch; try { - String command = shellcommand + ApplicationConstants.ROBOT_SPACE + robotvariables + robotScript; + String command = ApplicationConstants.ROBOT_SPACE + robotvariables + robotScript; LOGGER.info("Command execute to upload the script:" + command); - process = Runtime.getRuntime().exec(command); - inputStream = process.getInputStream(); + process = Runtime.getRuntime().exec(new String[] {getShellCommand(), getShellArg(), command}); + if(process != null) { + process.waitFor(); + inputStream = process.getInputStream(); + } + while((ch = inputStream.read()) != -1) { LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch)); } @@ -247,4 +244,24 @@ public class TaskExecution { } + private String getShellCommand() { + + String shellcommand = ApplicationConstants.SHELL_COMMAND; + if(SystemUtils.IS_OS_LINUX) { + shellcommand = ApplicationConstants.SHELL_COMMAND_BASH; + } + + return shellcommand; + } + + private String getShellArg() { + + String commandArg = "/c "; + if(SystemUtils.IS_OS_LINUX) { + commandArg = "-c "; + } + + return commandArg; + } + } diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/constants/ApplicationConstants.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/constants/ApplicationConstants.java index 3b19390..ff16220 100644 --- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/constants/ApplicationConstants.java +++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/constants/ApplicationConstants.java @@ -40,9 +40,9 @@ public class ApplicationConstants { public static final String MAIN_SCRIPT = "MAIN_SCRIPT"; - public static final String SHELL_COMMAND = "cmd.exe /c "; + public static final String SHELL_COMMAND = "cmd.exe "; - public static final String SHELL_COMMAND_BASH = ""; + public static final String SHELL_COMMAND_BASH = "/bin/bash "; public static final String CHARACTER = "character ..."; |