Solved

Hide error messages in batch file

Posted on 2014-10-01
5
479 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
  • 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 37

Expert Comment

by:Gerwin Jansen
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now