surely something is amiss
Results 1 to 2 of 2

Thread: surely something is amiss

  1. #1
    Join Date
    Feb 2026
    Posts
    1

    surely something is amiss

    I thought I understood the benefits of using a legacy, stable technology for simple tasks. I'm executing this DOS command:

    test.bat test Policy:

    while the contents of test.bat are:

    Code:
    @ECHO ON
    SETLOCAL EnableDelayedExpansion
    SET RESULT=%2
    IF '%RESULT%' == 'Policy:' SET RESULT=0
    SET CHK=%RESULT:~0,16%
    SET RC=%RESULT:~-10%
    ECHO %RESULT% %CHK% %RC%
    IF '%CHK%' == 'An error occurred' (
       ECHO %RC% 
       EXIT /B %RC%
    )
    REM
    and I get this:
    Code:
    Z:\WindowsSandbox\tools>SETLOCAL EnableDelayedExpansion
    
    Z:\WindowsSandbox\tools>SET RESULT=Policy:
    
    Z:\WindowsSandbox\tools>IF 'Policy:' == 'Policy:' SET RESULT=0
    
    Z:\WindowsSandbox\tools>SET CHK=0
    
    Z:\WindowsSandbox\tools>SET RC=0
    
    Z:\WindowsSandbox\tools>ECHO 0 0 0
    0 0 0
    
    Z:\WindowsSandbox\tools>IF '0' == 'An error occurred' (
    
    Z:\WindowsSandbox\tools>ECHO 0
    0
    
    Z:\WindowsSandbox\tools>EXIT /B 0
    
    Z:\WindowsSandbox\tools>

    Why does the IF compare result in the error exit? Thanks in advance for any clarity you can provide.

    Win11, 25H2. (the latest)

  2. #2
    Join Date
    Feb 2000
    Location
    Idaho Falls, Idaho, USA
    Posts
    18,420
    What results were you expecting that you did not get?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •