-1

Im trying to run an Error message if an command fails but i dont know how I know that you can use command1 && command2 if you want the second command to be only run if the first was successful but I dont know how to do this in batch. Also the things that i found didnt work like command1 | command2.

Im trying this right now for %%i in (*.osz) do start "" "%%~i | echo Error accrued! && Color c && timeout -1 >nul" but it dosent work.

Pls Help me

MushroomFX
  • 23
  • 9
  • 3
    `|` is for piping output, what you are thinking at is `||` instead. – dxiv Sep 16 '20 at 06:16
  • 1
    as commented above `command && echo success || echo error`. as you only want to test failure `command || (echo your code here)` I put within parens as you may want to do various things – elzooilogico Sep 16 '20 at 08:14

1 Answers1

1

You should look for "errorlevel", you will be able to test error code returned by your command : https://stackoverflow.com/a/6817833/6424355

command
if errorlevel 1 goto errorHandling
goto successHandling

In a loop you can call a subpart of your batch by using call :likeAGotoButYouWillGetBackHere

for ... call :likeAGotoButYouWillGetBackHere
goto eof
:likeAGotoButYouWillGetBackHere
...
goto eof   
Nitsuj
  • 11
  • 2