Reputation: 51
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
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:
What if you want to know if your program has stopped running again? You can do either:
Upvotes: 0
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