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 8775363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:47:02+00:00 2026-06-13T18:47:02+00:00

Can you see any reason why this would display 0 %ConnectDirectExe% -f%ConnectDirectCredentials% < %CurrentCDConfigFile%

  • 0

Can you see any reason why this would display 0

"%ConnectDirectExe%" -f"%ConnectDirectCredentials%" < "%CurrentCDConfigFile%" > "%CurrentCDTaskLogFile%"    
ECHO %errorlevel%  

yet this displays blank?

"%ConnectDirectExe%" -f"%ConnectDirectCredentials%" < "%CurrentCDConfigFile%" > "%CurrentCDTaskLogFile%"    
SET Result=%errorlevel%  
ECHO errorlevel is %Result%

Note that the “%ConnectDirectExe%” line in both cases exactly matches. If I invert the blocks to run in the opposite order, the results are similarly inverted, too.

Why can’t I store the result of %errorlevel% in Result and display it? It keeps on appearing as blank.

Update:

it seems like my SET statements aren’t being executed if they occur within the IF Block.

Given the following batch file, if.bat:

echo off

SET Result=1
ECHO ResultCaption1=%Result%

IF 1 equ 1 (
    SET Result=2
    ECHO ResultCaption2=%Result%
) else (
  ECHO 1 is not = 2
)

When I run it, i see this output:

C:\Batch>if.bat

C:\Batch>echo off
ResultCaption1=1
ResultCaption2=1

C:\Batch>

Shouldn’t the second ECHO display

ResultCaption2=2

?
  • 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-13T18:47:03+00:00Added an answer on June 13, 2026 at 6:47 pm

    I suspect your code is embedded within a parenthesised block, perhaps as part of an IF statement or a FOR loop. The problem with that is the expansion occurs when the line is parsed, and the entire block is parsed at once, before anything in the block is executed. So %errorlevel% will be the value before your command was executed, and %Result% will probably be undefined.

    The solution is to use delayed expansion, which must be enabled before it can be used. Type HELP SET from the command prompt to get more info about delayed expansion and how it can help when dealing with blocks of code.

    setlocal enableDelayedExpansion
    for ... in(...) do (
      "%ConnectDirectExe%" -f"%ConnectDirectCredentials%" < "%CurrentCDConfigFile%" > "%CurrentCDTaskLogFile%"
      SET Result=!errorlevel!
      ECHO errorlevel is !Result!
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't see any info about that. Where can I find the oldest date
There is code for save button, but I can't see any code behind the
Are boost ptime instances always UTC? I can't see any time zone info on
If you have used any decent java or .net IDE you can see the
Any idea why I can't see H1? <div id=getTheProducts style=clear: both; margin-top: 15px; margin-bottom:
Trying to replace any non alpha-numeric characters with a hyphen. Can't see why it
In Ruby, you can call Enumerable#any? on a enumerable object to see if any
To see if I can really take any benefit of native code (written C)
Everywhere I see, can't find any info about it. I need that people who
I can see the Graphical Layout of the XML file within the /res/layout folder,

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.