diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/Call.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/Call.java index 79ae40ddb5..e0ee8af4ac 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/Call.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/Call.java @@ -55,8 +55,7 @@ public class Call implements Statement { public String render(OsFamily family) { StringBuilder args = new StringBuilder(); for (String arg : this.args) { - args.append(String.format(" \"%s\"", Utils.replaceTokens(arg, ShellToken - .tokenValueMap(family)))); + args.append(" ").append(Utils.replaceTokens(arg, ShellToken.tokenValueMap(family))); } StringBuilder call = new StringBuilder(); call.append(Utils.replaceTokens(OS_TO_CALL.get(family), ImmutableMap.of("function", function, diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/ShellToken.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/ShellToken.java index d40fe2fa58..5e8197fb59 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/ShellToken.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/ShellToken.java @@ -149,7 +149,7 @@ public enum ShellToken { case END_SCRIPT: switch (family) { case WINDOWS: - return "exit 0\r\n"; + return "exit /b 0\r\n"; case UNIX: return "exit 0\n"; } @@ -170,7 +170,7 @@ public enum ShellToken { case EXIT: switch (family) { case WINDOWS: - return "exit"; + return "exit /b"; case UNIX: return "exit"; } diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java index 65e75d6151..f62f6244a1 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java @@ -215,8 +215,8 @@ public class Utils { } public static final Map OS_TO_ZERO_PATH = ImmutableMap.of(OsFamily.WINDOWS, - "set PATH=c:\\windows\\;C:\\windows\\system32\r\n", OsFamily.UNIX, - "export PATH=/usr/ucb/bin:/bin:/usr/bin:/usr/sbin\n"); + "set PATH=c:\\windows\\;C:\\windows\\system32;c:\\windows\\system32\\wbem\r\n", + OsFamily.UNIX, "export PATH=/usr/ucb/bin:/bin:/usr/bin:/usr/sbin\n"); /** * @return line used to zero out the path of the script such that basic commands such as unix ps diff --git a/scriptbuilder/src/main/resources/functions/abort.cmd b/scriptbuilder/src/main/resources/functions/abort.cmd index 3d79b48c4f..9ca47282a3 100644 --- a/scriptbuilder/src/main/resources/functions/abort.cmd +++ b/scriptbuilder/src/main/resources/functions/abort.cmd @@ -1,3 +1,3 @@ :abort echo aborting: %EXCEPTION% - exit 1 + exit /b 1 diff --git a/scriptbuilder/src/main/resources/functions/findPid.cmd b/scriptbuilder/src/main/resources/functions/findPid.cmd index 7653c210e5..149a26c1c7 100644 --- a/scriptbuilder/src/main/resources/functions/findPid.cmd +++ b/scriptbuilder/src/main/resources/functions/findPid.cmd @@ -1,16 +1,14 @@ :findPid set FOUND_PID= - SETLOCAL - set _pid= set _expression=%1 shift - set FIND_PROCESS=wmic process where (CommandLine like "%_expression%%%") get ProcessId - for /f "usebackq skip=1" %%a in (`cmd /c "%FIND_PROCESS% 2>NUL"`) do ( - if not defined _proc ( - set _pid=%%a - goto :done - ) + set FIND_PROCESS=TASKLIST /FI "WINDOWTITLE eq %_expression%" /NH + FOR /F "usebackq tokens=2 delims= " %%A IN (`cmd /c "%FIND_PROCESS% 2>NUL"`) DO ( + SET FOUND_PID=%%A + ) + if defined FOUND_PID ( + exit /b 0 + ) else ( + set EXCEPTION=%_expression% not found + exit /b 1 ) - :done - ENDLOCAL&SET FOUND_PID=%_pid% - exit /b 0 diff --git a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/domain/CallTest.java b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/domain/CallTest.java index 298c904c42..9bc4c7958e 100644 --- a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/domain/CallTest.java +++ b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/domain/CallTest.java @@ -45,12 +45,12 @@ public class CallTest { public void testCallArgsUNIX() { Call call = new Call("help", "me", "rhonda"); - assertEquals(call.render(OsFamily.UNIX), "help \"me\" \"rhonda\" || return 1\n"); + assertEquals(call.render(OsFamily.UNIX), "help me rhonda || return 1\n"); } public void testCallArgsWINDOWS() { Call call = new Call("help", "me", "rhonda"); assertEquals(call.render(OsFamily.WINDOWS), - "call :help \"me\" \"rhonda\"\r\nif errorlevel 1 goto abort\r\n"); + "call :help me rhonda\r\nif errorlevel 1 goto abort\r\n"); } } diff --git a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/domain/ShellTokenTest.java b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/domain/ShellTokenTest.java index ab69032114..4aa1849075 100644 --- a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/domain/ShellTokenTest.java +++ b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/domain/ShellTokenTest.java @@ -55,11 +55,11 @@ public class ShellTokenTest { public void testTokenValueMapWindows() { Map expected = new ImmutableMap.Builder().put("fs", "\\") .put("ps", ";").put("lf", "\r\n").put("sh", "cmd").put("source", "@call").put("rem", - "@rem").put("args", "%*").put("varl", "%").put("exit", "exit").put("varr", + "@rem").put("args", "%*").put("varl", "%").put("exit", "exit /b").put("varr", "%").put("libraryPathVariable", "PATH").put("return", "exit /b").put("vq", "").put("beginFunctions", "GOTO FUNCTION_END\r\n").put("endFunctions", ":FUNCTION_END\r\n").put("beginScript", "@echo off\r\n").put("endScript", - "exit 0\r\n").put("fncl", ":").put("fncr", "\r\n").put("fnce", + "exit /b 0\r\n").put("fncl", ":").put("fncr", "\r\n").put("fnce", " exit /b 0\r\n").put("export", "set").build(); assertEquals(ShellToken.tokenValueMap(OsFamily.WINDOWS), expected); diff --git a/scriptbuilder/src/test/resources/test_find_pid.bash b/scriptbuilder/src/test/resources/test_find_pid.bash index 802a7f75a2..4a0f92692b 100644 --- a/scriptbuilder/src/test/resources/test_find_pid.bash +++ b/scriptbuilder/src/test/resources/test_find_pid.bash @@ -23,6 +23,6 @@ function findPid { } } export PATH=/usr/ucb/bin:/bin:/usr/bin:/usr/sbin -findPid "$@" || exit 1 +findPid $@ || exit 1 echo $FOUND_PID exit 0 diff --git a/scriptbuilder/src/test/resources/test_find_pid.cmd b/scriptbuilder/src/test/resources/test_find_pid.cmd index 5b3d075815..99a931b53c 100644 --- a/scriptbuilder/src/test/resources/test_find_pid.cmd +++ b/scriptbuilder/src/test/resources/test_find_pid.cmd @@ -5,26 +5,24 @@ set PATH= GOTO FUNCTION_END :abort echo aborting: %EXCEPTION% - exit 1 + exit /b 1 :findPid set FOUND_PID= - SETLOCAL - set _pid= set _expression=%1 shift - set FIND_PROCESS=wmic process where (CommandLine like "%_expression%%%") get ProcessId - for /f "usebackq skip=1" %%a in (`cmd /c "%FIND_PROCESS% 2>NUL"`) do ( - if not defined _proc ( - set _pid=%%a - goto :done - ) + set FIND_PROCESS=TASKLIST /FI "WINDOWTITLE eq %_expression%" /NH + FOR /F "usebackq tokens=2 delims= " %%A IN (`cmd /c "%FIND_PROCESS% 2>NUL"`) DO ( + SET FOUND_PID=%%A + ) + if defined FOUND_PID ( + exit /b 0 + ) else ( + set EXCEPTION=%_expression% not found + exit /b 1 ) - :done - ENDLOCAL&SET FOUND_PID=%_pid% - exit /b 0 :FUNCTION_END -set PATH=c:\windows\;C:\windows\system32 -call :findPid "%*" +set PATH=c:\windows\;C:\windows\system32;c:\windows\system32\wbem +call :findPid %* if errorlevel 1 goto abort echo %FOUND_PID% -exit 0 +exit /b 0 diff --git a/scriptbuilder/src/test/resources/test_script.cmd b/scriptbuilder/src/test/resources/test_script.cmd index 843a6aebd9..df9b3fbdd9 100644 --- a/scriptbuilder/src/test/resources/test_script.cmd +++ b/scriptbuilder/src/test/resources/test_script.cmd @@ -5,12 +5,12 @@ set PATH= GOTO FUNCTION_END :abort echo aborting: %EXCEPTION% - exit 1 + exit /b 1 :default set JAVA_HOME=/apps/jdk1.6 exit /b 0 :FUNCTION_END -set PATH=c:\windows\;C:\windows\system32 +set PATH=c:\windows\;C:\windows\system32;c:\windows\system32\wbem goto CASE%1 :CASE_start echo started @@ -19,4 +19,4 @@ goto CASE%1 echo stopped GOTO END_SWITCH :END_SWITCH -exit 0 +exit /b 0