Solved

Hide error messages in batch file

Posted on 2014-10-01
5
554 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 500 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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