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?
Ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
Steve
To redirect the error output of your reg query in batchfile2.bat:
reg query hklm\software\not_existing 2> log.txt
reg query hklm\software\not_existing