0

So, I am running a .bat file that gives multiple inputs at one go and divides 100 by each number and I print the status

division.exe divide-100 -numbers 5,0,10,45 

if %ERRORLEVEL% == 0 (
    echo Success.
) else (
    echo Failed.
)

but it gives the status of only the last input.

Is there a way to get the status for all the inputs???

Like here it is giving "Success".

It should give -

Success

Failed

Success

Success

AniAxe
  • 5
  • 3
  • does your `.exe` give any output (if yes, how would it look like) or just an errorlevel? – Stephan Aug 24 '23 at 06:50
  • @Stephan yes my exe gives output for all (it's just status msg [number + "Divides 100"] in try block, in catch [number + "cant divide 100"]), it's just that i want .bat file to get that – AniAxe Aug 24 '23 at 06:56
  • Should be a one-liner: `for /f "delims=" %%a in ('division.exe divide-100 -numbers 5,0,10,45') do echo %%a|find "Divides" >nul && echo Success||echo Failed`. Not sure if it works without adaption without actually seeing the exact output. – Stephan Aug 24 '23 at 07:00

1 Answers1

0

I think you can iterate through each number in the numbers variable, execute the division.exe command with that number, and check the status using ERRORLEVEL to determine success!

something like this :

@echo off

set "numbers=5,0,10,45"

for %%i in (%numbers%) do (
    division.exe divide-100 -numbers %%i

    if ERRORLEVEL 1 (
        echo Failed.
    ) else (
        echo Success.
    )
)
Freeman
  • 9,464
  • 7
  • 35
  • 58
  • Will not work. Standard [delayed expansion trap error](https://stackoverflow.com/a/30284028/2128947) – Magoo Aug 24 '23 at 08:54
  • Change your IF by: `if ERRORLEVEL 1 ( echo Failed. ) else ( echo Success. )` – Aacini Aug 24 '23 at 12:29
  • Yes,you are correct. The standard delayed expansion can cause issues in this case,I am currently on a MacBook and did not have the opportunity to test it, thank you for your guidance! – Freeman Aug 24 '23 at 12:58