I'm just learning batch script. I'm reviewing the getJavaVersion.bat script on GitHub. I understood what the 2^>^&1
expression in the following line of code is used for. But I couldn't understand how this syntax (2^>^&1
) is used. Can you help me with this?
for /f tokens^=2-5^ delims^=.-_^" %%j in ('java -fullversion 2^>^&1') do set "jver=%%j%%k%%l%%m"
The commands below show the generated values:
for /f "delims=" %%i in ('java -fullversion') do set output=%%i
echo %output%
:: OUTPUT >> java full version "18.0.1.1+2-6"
for /f tokens^=2-5^ delims^=.-_^" %%j in ('java -fullversion 2^>^&1') do set "jver=%%j%%k%%l%%m"
echo %jver%
:: OUTPUT >> 18011+2