?
Solved

Hide error messages in batch file

Posted on 2014-10-01
5
Medium Priority
?
602 Views
Last Modified: 2014-11-03
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
Comment
Question by:zequestioner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 40354969
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40354973
Pah, autocorrect being helpful there on mobile... Hopefully get the idea, say if not sure!
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40354976
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40354986
To add to that to hide on the individual command or whole batch file use 2>nul

Steve
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40360584
To redirect the error output of your reg query in batchfile2.bat:

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

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question