Skip to content

subtle bug in Java version discovery, the java.exe in the for statement should be changed to .\java.exe #351

@marcmcd

Description

@marcmcd

In scripts\StartIBC.bat, there's the line

for /f "tokens=1,2 delims== usebackq" %%A in (`java.exe -XshowSettings:properties 2^>^&1 ^| findstr /C:"java.version ="`) do set java_version=%%B

the java.exe in the for statement should be changed to .\java.exe because just java.exe can cause the warning:

'java.exe' is not recognized as an internal or external command,
operable program or batch file.

this causes the variable java_version to never be set, and the later line

if not "%java_version:1.8=%"=="%java_version%" set moduleAccess=

then crashes the script with the error set was unexpected at this time, neatly escalating a warning into a crash, and
needless to say, the IB TWS or Gateway, which are called later, never run.

This 'java.exe' is not recognized issue can happen if the cmd or Powershell environment that runs StartIBC.bat is not set up correctly.
Using just java.exe can work if your terminal's PATH includes . or has other settings that allow current-directory search,
or your terminal has system-wide PATH that includes common directories. If this is not the case, then it may not work, which has definitely happened on my Windows 10 box and the fix below worked.

The fix is to change the java.exe in

:: temporarily change the current working directory because using "%JAVA_PATH%\java.exe" in the following 'for' statement causes an error
pushd "%JAVA_PATH%"
for /f "tokens=1,2 delims== usebackq" %%A in (`java.exe -XshowSettings:properties 2^>^&1 ^| findstr /C:"java.version ="`) do set java_version=%%B
:: restore the original current working directory
popd

to .\java.exe as follows

:: temporarily change the current working directory because using "%JAVA_PATH%\java.exe" in the following 'for' statement causes an error
pushd "%JAVA_PATH%"
for /f "tokens=1,2 delims== usebackq" %%A in (`.\java.exe -XshowSettings:properties 2^>^&1 ^| findstr /C:"java.version ="`) do set java_version=%%B
:: restore the original current working directory
popd

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions