mirror of https://github.com/apache/jclouds.git
Issue 126: findPid on windows now matches on window title. fixed error where script exit quit the calling shell in windows
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2354 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
e62fe3f6e4
commit
4b24b990be
|
@ -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,
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -215,8 +215,8 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static final Map<OsFamily, String> 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
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
:abort
|
||||
echo aborting: %EXCEPTION%
|
||||
exit 1
|
||||
exit /b 1
|
||||
|
|
|
@ -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
|
||||
)
|
||||
)
|
||||
:done
|
||||
ENDLOCAL&SET FOUND_PID=%_pid%
|
||||
if defined FOUND_PID (
|
||||
exit /b 0
|
||||
) else (
|
||||
set EXCEPTION=%_expression% not found
|
||||
exit /b 1
|
||||
)
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,11 +55,11 @@ public class ShellTokenTest {
|
|||
public void testTokenValueMapWindows() {
|
||||
Map<String, String> expected = new ImmutableMap.Builder<String, String>().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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
)
|
||||
)
|
||||
:done
|
||||
ENDLOCAL&SET FOUND_PID=%_pid%
|
||||
if defined FOUND_PID (
|
||||
exit /b 0
|
||||
) else (
|
||||
set EXCEPTION=%_expression% not found
|
||||
exit /b 1
|
||||
)
|
||||
: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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue