Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress error notification in batch file?

I am trying to write a batch file (my first batch file) that runs a program many times. Unfortunately, the program that is being repeatedly run sometimes crashes with the error "[program] has encountered a problem and needs to close ...etc" (event 1000). This is a problem because in order to proceed I would have to manually click out of the error, and then the loop resumes until another error occurs or the loop is finished.

cd C:\Users\username\Desktop\test_file
for %%i in ( 1 2 3 ) do (
    mkdir output%%i
    run_program.command -f envt_file.txt -b instructions.txt -p output%%i
)
cd ..

Is there some way to run "run_program.command" and suppress any error messages that may appear?

(I have seen some solutions that may work, but I am afraid to test some of them because I am new at this and still kind of afraid of batch files!)

(I am using Windows 10)

like image 406
LaPlaya Avatar asked Feb 16 '26 07:02

LaPlaya


1 Answers

In general, append >nul to an instruction to dispose of messages generated, or use 2>nul (the 2 and > must be consecutive to dispose of error messages.

Sometimes, error messages are generated as standard messages, so

run_program.command -f envt_file.txt -b instructions.txt -p output%%i >nul

should work if everyone follows the rules

run_program.command -f envt_file.txt -b instructions.txt -p output%%i >nul

may be required

run_program.command -f envt_file.txt -b instructions.txt -p output%%i >nul 2>nul

Is belt-and-braces.

Really depends on whether you want to dispose of error messages only or all messages.

like image 129
Magoo Avatar answered Feb 19 '26 01:02

Magoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!