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

  • SEARCH
  • Home
  • 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 8241815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:57:25+00:00 2026-06-07T20:57:25+00:00

I am on Windows 7 Enterprise and calling a jar from batch file which

  • 0

I am on Windows 7 Enterprise and calling a jar from batch file which returns 0, 1 or 2 depending on condition, I have used “System.exit” for same,

following is my batch script

@echo off

java -jar "test.jar" %*
set exitcode=%ERRORLEVEL%
echo here is 1st exit code %exitcode%
if %exitcode% == 2 (    
        VERIFY > nul
        set exitcode=%ERRORLEVEL%
        echo here is 2nd exit code after VERIFY %exitcode%
        call test.exe %*
        echo here is 2nd exit code %ERRORLEVEL% 

    if %ERRORLEVEL% == 0    (
           cmd /c "exit /b 0"
           call test1.exe -f
           echo here is 3rd exit code %errorlevel%
    )
)exit /b %errorlevel%

What I am doing in above code is, calling a jar and depending on errorlevel it returns I am calling another exe and again depending on errorlevel of that exe I am calling third exe. Issue is, exitcode I am getting is first exit code assigned i.e. if test.jar exists with 2 even after successful execution of other exes errorlevel doesn’t get changed. And third exe never gets executed. Tried different approaches of calling a

cmd exit /b 0

for resetting errorlevel to 0 but its not working.

  • 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-07T20:57:27+00:00Added an answer on June 7, 2026 at 8:57 pm

    Your problem is that cmd expands environment variables immediately when a statement is parsed, not when it’s executed. A statement in this sense includes the whole if including the blocks. You need to use delayed expansion, so stick the following at the start of your batch:

    setlocal enabledelayedexpansion
    

    and then use !errorlevel! instead of %errorlevel% within the conditional statement (likewise for exitcode).

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

Sidebar

Related Questions

I am using Windows 7 Enterprise 32 bit. I have used Windows command line,
I am running windows 7 x64 enterprise. I have Office 2010 x64 installed. I
Our company recently upgraded from Windows XP to Windows 7 Enterprise. The JDK installation
I have Visual Studio 2010 Ultimate on Windows 7 Enterprise running on a x86
I have a query which, for each Operating System, provides the total count of
System is Windows Server 2008 R2 Enterprise 64 bit Running Microsoft SQL Server 2008
I have Visual Studio 2008 installed on a Windows 2008 Enterprise Server. I am
my host machine is a 64bit Windows 7 Enterprise device. I have vmware player
I’m using a Windows 7 Enterprise edition 64 bit, the firewall means certain update
I'm running 32-bit Windows 7 Enterprise and CodeBlocks 10.05. I followed this tutorial to

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.