Make sure you are using Java 8 JRE
In your script, replace the word java with the java 8 path
Something like
"C:\Program Files\Java\jre1.8.0_311\bin\javaw.exe" -server -Xmx4G -Xms4G -Dlog4j.configurationFile=log4jformattingfix.xml -jar forge-1.12.2-14.23.5.2860.jar nogui
pause
Make sure the Java 8 path is correct and keep the quotation marks