Here is one way to do it:
In Java code :
At the end of the program put this line
System.exit(789);
Here 789 is the value you would return to your batch file.
In the batch file:
@echo off
java Test %1
set exitcode=%ERRORLEVEL%
echo %exitcode%
Here
java Test %1 is the usual java execution with argument passed from batch file where %1 will map to the first parameter passed to the batch file from command prompt (like wise you could have %2 etc ... Check this article ).
ERRORLEVEL is the standard batch variable use to store the value returned from java
Assuming that your batch file name is Test.bat, you run this from command prompt batch as
Test 456
EDIT:Example for adding two numbers
Example.java
public class Example extends TestBase<String>
{
public static void main(String[] arg){
int result = Integer.parseInt(arg[0].trim()) ;+Integer.parseInt(arg[1].trim())
System.exit(result);
}
}
Compile this file and generate a class file Example.class
Batch file :
Example.bat
@echo off
java Example %1 %2
set exitcode=%ERRORLEVEL%
echo %exitcode%
Put this batch file and Example.class in a folder. Open command prompt from that folder and run as follows
Example 111 222
This will print the addition of these two numbers