[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 731
  • Last Modified:

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?
0
zequestioner
Asked:
zequestioner
  • 3
1 Solution
 
Steve KnightIT ConsultancyCommented:
Sure. In the same way that > redirects normal output 2> redirects errors, so you can send to two places with:

Batch.CND > log.text 2> errors.text

If you want them together then use this syntax to redirect errors to standard output an then to your file:

Batch.cmd > log.txt 2>&1

Steve
0
 
Steve KnightIT ConsultancyCommented:
Pah, autocorrect being helpful there on mobile... Hopefully get the idea, say if not sure!
0
 
Gabriel CliftonCommented:
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
0
 
Steve KnightIT ConsultancyCommented:
To add to that to hide on the individual command or whole batch file use 2>nul

Steve
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
To redirect the error output of your reg query in batchfile2.bat:

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now