Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is one way to do it:</p> <p><strong>In Java code :</strong></p> <p>At the end of the program put this line </p> <pre><code>System.exit(789); </code></pre> <p>Here <code>789</code> is the value you would return to your batch file. </p> <p><strong>In the batch file:</strong> </p> <pre><code>@echo off java Test %1 set exitcode=%ERRORLEVEL% echo %exitcode% </code></pre> <p>Here</p> <p><code>java Test %1</code> 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 (<em>like wise you could have %2 etc</em> ... <a href="http://www.windowsitpro.com/article/server-management/how-do-i-pass-parameters-to-a-batch-file-" rel="nofollow">Check this article</a> ). </p> <p><code>ERRORLEVEL</code> is the standard batch variable use to store the value returned from java</p> <p>Assuming that your batch file name is <code>Test.bat</code>, you run this from command prompt batch as </p> <p><code>Test 456</code></p> <p><strong>EDIT</strong>:Example for adding two numbers </p> <p>Example.java</p> <pre><code>public class Example extends TestBase&lt;String&gt; { public static void main(String[] arg){ int result = Integer.parseInt(arg[0].trim()) ;+Integer.parseInt(arg[1].trim()) System.exit(result); } } </code></pre> <p>Compile this file and generate a class file Example.class</p> <p>Batch file :</p> <p>Example.bat</p> <pre><code>@echo off java Example %1 %2 set exitcode=%ERRORLEVEL% echo %exitcode% </code></pre> <p>Put this batch file and Example.class in a folder. Open command prompt from that folder and run as follows</p> <pre><code>Example 111 222 </code></pre> <p>This will print the addition of these two numbers </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload