From 8403c23125fdc6f141891b784b0183e33dca6d06 Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Tue, 13 Nov 2018 17:16:58 +0800 Subject: [PATCH] refactor as.bat, detect telnt, support jdk11. fix #181 --- bin/as.bat | 98 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/bin/as.bat b/bin/as.bat index a56f44d8..103ebccb 100644 --- a/bin/as.bat +++ b/bin/as.bat @@ -11,79 +11,83 @@ REM ---------------------------------------------------------------------------- set ERROR_CODE=0 -:init -REM Decide how to startup depending on the version of windows - -REM -- Win98ME -if NOT "%OS%"=="Windows_NT" goto Win9xArg - -REM set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal -goto WinNTGetScriptDir - -:Win9xArg -REM Slurp the command line arguments. This loop allows for an unlimited number -REM of arguments (up to the command line limit, anyway). -set BASEDIR=%CD% -goto repoSetup - -:WinNTGetScriptDir set BASEDIR=%~dp0 -:repoSetup + +if ["%~1"]==[""] ( + echo Example: + echo %~nx0 452 + echo %~nx0 452 --ignore-tools # for jdk 9/10/11 + echo( + echo Need the pid argument, you can run jps to list all java process ids. + goto exit_bat +) + set AGENT_JAR=%BASEDIR%\arthas-agent.jar set CORE_JAR=%BASEDIR%\arthas-core.jar set PID=%1 +echo %PID%| findstr /r "^[1-9][0-9]*$">nul + +if %errorlevel% neq 0 ( + echo PID is not valid number! + echo Example: + echo %~nx0 452 + echo %~nx0 452 --ignore-tools # for jdk 9/10/11 + echo( + echo Need the pid argument, you can run jps to list all java process ids. + goto exit_bat +) + + +if "%2"=="--ignore-tools" ( + set ignoreTools=1 +) else ( + set ignoreTools=0 +) + REM Setup JAVA_HOME if "%JAVA_HOME%" == "" goto noJavaHome if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome -if not exist "%JAVA_HOME%\lib\tools.jar" goto noJavaHome +if %ignoreTools% == 1 ( + echo Ignore tools.jar, make sure the java version ^>^= 9 +) else ( + if not exist "%JAVA_HOME%\lib\tools.jar" ( + echo Can not find lib\tools.jar under %JAVA_HOME%! + echo If java version ^<^= 1.8, please make sure JAVA_HOME point to a JDK not a JRE. + echo If java version ^>^= 9, try to run as.bat ^ --ignore-tools + goto exit_bat + ) + set BOOT_CLASSPATH="-Xbootclasspath/a:%JAVA_HOME%\lib\tools.jar" +) + set JAVACMD="%JAVA_HOME%\bin\java" -set BOOT_CLASSPATH="-Xbootclasspath/a:%JAVA_HOME%\lib\tools.jar" goto okJava :noJavaHome echo The JAVA_HOME environment variable is not defined correctly. echo It is needed to run this program. echo NB: JAVA_HOME should point to a JDK not a JRE. -goto exit +goto exit_bat :okJava set JAVACMD="%JAVA_HOME%"\bin\java -REM Reaching here means variables are defined and arguments have been captured -:endInit - %JAVACMD% -Dfile.encoding=UTF-8 %BOOT_CLASSPATH% -jar "%CORE_JAR%" -pid "%PID%" -target-ip 127.0.0.1 -telnet-port 3658 -http-port 8563 -core "%CORE_JAR%" -agent "%AGENT_JAR%" -if %ERRORLEVEL% NEQ 0 goto error +if %ERRORLEVEL% NEQ 0 goto exit_bat goto attachSuccess -:error -if "%OS%"=="Windows_NT" endlocal -set ERROR_CODE=%ERRORLEVEL% -goto endNT :attachSuccess -telnet 127.0.0.1 3658 - -REM set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" goto endNT - -REM For old DOS remove the set variables from ENV - we assume they were not set -REM before we started - at least we don't leave any baggage around -goto postExec - -:endNT -REM If error code is set to 1 then the endlocal was done already in :error. -if %ERROR_CODE% EQU 0 endlocal - - -:postExec - -if "%FORCE_EXIT_ON_ERROR%" == "on" ( - if %ERROR_CODE% NEQ 0 exit %ERROR_CODE% +WHERE telnet +IF %ERRORLEVEL% NEQ 0 ( + ECHO telnet wasn't found, please google how to install telnet under windows. + ECHO Try to visit http://127.0.0.1:8563 to connecto arthas server. + start http://127.0.0.1:8563 +) else ( + telnet 127.0.0.1 3658 ) +:exit_bat exit /B %ERROR_CODE%