BASH to BATCH java
There's this BASH file:
#!/bin/bash set -eu DIR=`dirname $0` JAR=$DIR/myjar.jar CLASSPATH=$JAR:./ HEAP_SIZE=-size java $HEAP_SIZE -cp $CLASSPATH something.something2 "$@"
That I want to turn into a .bat file to run on windows This is what I have so far:
@ECHO OFF set DIR = %cd% set JAR = DIR/myjar.jar set CLASSPATH = %JAR%:./ set HEAP_SIZE = -size java %HEAP_SIZE% -cp %CLASSPATH% something.something2
How would I complete it to have the same behavior as the bash file?
%CD% can work, but your bash script seems to be setting the directory based off the path of the script (i.e., argument in $0) and not the current directory. To use the same directory as the batch file, you use %~dp0.
You missed % around your DIR variable when you wanted to expand the value.
You shouldn't have spaces around equal signs in your set statements.
The equivalent of $@ in batch is %*.
You should quote your %CLASSPATH%. On Windows you are much more likely to encounter paths with spaces in them.
@ECHO OFF set "DIR=%~dp0" set "JAR=%DIR%/myjar.jar" set "CLASSPATH=%JAR%:./" set "HEAP_SIZE=-size" java %HEAP_SIZE% -cp "%CLASSPATH%" something.something2 %*