LaPlaya
LaPlaya

Reputation: 51

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)

Upvotes: 3

Views: 14296

Answers (2)

brokestudent
brokestudent

Reputation: 1

This question has been asked around so I'm going to answer it here for Internet records. I have the same question and this is the solution given to me. Should work on Windows 10:

  1. Open "Group Policy Editor" (gpedit.msc)
  2. Find your way to "Computer config" -> "Admin templates" -> "Windows components" -> "Windows error reporting"
  3. Enable this settings, "Prevent display of the user interface for critical errors"
  4. Optional: enable this one, "Disable windows error reporting" will turn off any error reporting.

What if you want to know if your program has stopped running again? You can do either:

  • Open "Event Viewer" to see a log of everything or:
  • Open "Control Panel" -> "Security and Maintenance" -> "Maintenance" -> "View reliability history"

Upvotes: 0

Magoo
Magoo

Reputation: 80013

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.

Upvotes: 5

Related Questions