Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8450755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:03:34+00:00 2026-06-10T11:03:34+00:00

I have to execute a java code using batch script where java code has

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:03:35+00:00Added an answer on June 10, 2026 at 11:03 am

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using java Runtime.exec() method to execute bat file,in bat file i have
I have generated a java code from matlab and while executing the java code
I have this issue: first, I execute a SQL query using Java and then
I was wondering what would be the best way to execute a java-script code
I want to execute some Unix commands from the java code. I want to
I'm working on some Xquery code (using SAXON) to execute a simple XQuery file
I have this chess engine Rybka.exe, that i have to execute in java Here
I have a Java program that executes from Spring Qquartz every 20 seconds. Sometimes
I have an Execute SQL task (SQL 2008) where I'm using two SSIS variables
I have the Execute SQL Script package that contains the script to insert about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.