Solved

Hide error messages in batch file

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

17 Experts available now in Live!

Get 1:1 Help Now