|
1 | 1 | @echo off
|
2 | 2 | setlocal enabledelayedexpansion
|
3 | 3 |
|
| 4 | +REM ======================================================== |
| 5 | +REM Function: ensureJava |
| 6 | +REM Usage: call :ensureJava path\to\hs_err_file.txt |
| 7 | +REM If 'java' is not found in PATH, extract JAVA_HOME from the |
| 8 | +REM hs_err file and update PATH accordingly. |
| 9 | +REM ======================================================== |
| 10 | +:ensureJava |
| 11 | + REM Check if java is available |
| 12 | + where java >nul 2>&1 |
| 13 | + if %ERRORLEVEL%==0 ( |
| 14 | + REM Java found; nothing to do. |
| 15 | + goto :EOF |
| 16 | + ) |
| 17 | + |
| 18 | + REM Java not found; try to extract JAVA_HOME from the hs_err file passed as parameter. |
| 19 | + if "%~1"=="" ( |
| 20 | + echo Error: No hs_err file provided. |
| 21 | + exit /b 1 |
| 22 | + ) |
| 23 | + |
| 24 | + REM Use findstr to locate the line with JAVA_HOME. |
| 25 | + for /f "tokens=2 delims==" %%A in ('findstr "JAVA_HOME" "%~1"') do ( |
| 26 | + set "JAVA_HOME=%%A" |
| 27 | + ) |
| 28 | + |
| 29 | + REM Check if JAVA_HOME was found |
| 30 | + if not defined JAVA_HOME ( |
| 31 | + echo Error: Java executable not found. Cannot upload error file. |
| 32 | + exit /b 1 |
| 33 | + ) |
| 34 | + |
| 35 | + REM Optionally, remove any surrounding quotes or spaces: |
| 36 | + set "JAVA_HOME=%JAVA_HOME:"=%" |
| 37 | + for /f "tokens=* delims= " %%A in ("%JAVA_HOME%") do set "JAVA_HOME=%%A" |
| 38 | + |
| 39 | + REM Prepend JAVA_HOME\bin to PATH |
| 40 | + set "PATH=%JAVA_HOME%\bin;%PATH%" |
| 41 | + goto :EOF |
| 42 | + |
| 43 | + |
4 | 44 | :: Check if PID is provided
|
5 | 45 | if "%1"=="" (
|
6 | 46 | echo "Error: No PID provided. Running in legacy mode."
|
| 47 | + call :ensureJava "!JAVA_ERROR_FILE!" |
7 | 48 | java -jar "!AGENT_JAR!" uploadCrash "!JAVA_ERROR_FILE!"
|
8 | 49 | if %ERRORLEVEL% EQU 0 (
|
9 | 50 | echo "Uploaded error file \"!JAVA_ERROR_FILE!\""
|
@@ -38,10 +79,11 @@ for /f "tokens=1,2 delims=: " %%a in (%configFile%.cfg) do (
|
38 | 79 | :: Debug: Print the loaded values (Optional)
|
39 | 80 | echo Agent Jar: %agent%
|
40 | 81 | echo Error Log: %hs_err%
|
| 82 | +echo JAVA_HOME: %java_home% |
41 | 83 | echo PID: %PID%
|
42 | 84 |
|
43 | 85 | :: Execute the Java command with the loaded values
|
44 |
| -java -jar "%agent%" uploadCrash "%hs_err%" |
| 86 | +%java_home%\bin\java -jar "%agent%" uploadCrash "%hs_err%" |
45 | 87 | set RC=%ERRORLEVEL%
|
46 | 88 | del "%configFile%" :: Clean up the configuration file
|
47 | 89 | if %RC% EQU 0 (
|
|
0 commit comments