I have to execute a java code using batch script where java code has to take a variable value generated from the .bat file and execute java code and then return the another variable value back to .bat .
In say, exec.bat file i l get a value “456” .this “456” has to be sent to java file and there after execution we get another value “789” .And I want this “789” to be return back to exe.bat .
Please let me know the code and syntax to be written in both java and batch file.
Thanks in Advance
Here is one way to do it:
In Java code :
At the end of the program put this line
Here
789is the value you would return to your batch file.In the batch file:
Here
java Test %1is 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 ).ERRORLEVELis the standard batch variable use to store the value returned from javaAssuming that your batch file name is
Test.bat, you run this from command prompt batch asTest 456EDIT:Example for adding two numbers
Example.java
Compile this file and generate a class file Example.class
Batch file :
Example.bat
Put this batch file and Example.class in a folder. Open command prompt from that folder and run as follows
This will print the addition of these two numbers