Link to home
Start Free TrialLog in
Avatar of zequestioner
zequestioner

asked on

Hide error messages in batch file

I have a batch file that runs another batch file. for example batchfile1.bat > log.txt and inside of batchfile1.bat there is a call to another batch file, batchfile2.bat. Inside batchfile2.bat there is a registry query (regquery command) that fails sometimes and it displays the error inside of the console running batchfile1.bat. I would like to redirect this error to the log file or I would like to hide it completely.

Ideas?
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Pah, autocorrect being helpful there on mobile... Hopefully get the idea, say if not sure!
echo off only prevents the printing of commands, not results. To hide the result of a command add >nul to the end of the line, and to hide errors add 2>nul.
Example:
If exist C:\Random echo Random found >nul 2>nul
To add to that to hide on the individual command or whole batch file use 2>nul

Steve
To redirect the error output of your reg query in batchfile2.bat:

reg query hklm\software\not_existing 2> log.txt