Answer the question
In order to leave comments, you need to log in
How to write a condition in a bat file?
I am running a bat file.
If an error occurs during execution, I throw it on the error label .
ping -invalid-arg || goto error
But how to make a condition: if there is no error at this moment, transfer it to the next label?
those. I need a solution
if the file gives an error when executed, throw it on the error label .
if the file does not give an error, either we transfer it to the next label or, even more simply, we continue execution.
The main task is to catch the error and throw it on the label for further work of the file.
Answer the question
In order to leave comments, you need to log in
I found a solution!
We check for errors, if there are any, then ERRORLEVEL 1 will work if there is no ERRORLEVEL 0 .
Accordingly, we assign different labels for each of them.
if ERRORLEVEL 1 goto answer1
if ERRORLEVEL 0 goto answer0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question