Link to home
Start Free TrialLog in
Avatar of NCHCIT
NCHCITFlag for United States of America

asked on

Hiding Output in Batch File Script

From :
https://www.experts-exchange.com/questions/10698621/hiding-output-in-batch-file-can't-find-ctty.html?sfQueryTermInfo=1+batch+error+file+hide+script
I see how to hide the output in a batch file.
Do I need to add that code to each line for which I want to hide the output, or can I add it to one place in the script?  (For Win XP)
ASKER CERTIFIED SOLUTION
Avatar of usarian
usarian
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NCHCIT

ASKER

I've got ECHO OFF preceding all commands in the script, but it only hides the commands.  When I use an ATTRIB command on a directory, not wanting to change the attributes for hidden files, I get a ton of output for all hidden files whose attributes are not being changed, regardless of the ECHO OFF command.
Using >> (would that be considered a switch or command or something else?) took care of the job nicely.
Do I need to use that for every command whose output I want to hide?
To suppress both output and errors without creating a log file, append the following to each command:
> NUL 2>&1

Yes, you need to use it for each command whose output you want to hide.

See here for more information on redirection:
http://www.ss64.com/ntsyntax/redirection.html
You can use DOS redirector with NUL keyword (or you can use file name to save output in it) to hide displaying any message on screen (with the end of every command that show output on screen)

Like:

CommandHere >NUL
:: Above >NUL statement will hide output of if command executes successfully.

CommandHere 2>NUL
:: Above 2>NUL statement will hide error message of if command fails

CommandHere 2>NUL >NUL
:: Above 2>NUL >NUL statement will hides both successful or error message.

Hope this helps!
Farhan
Avatar of NCHCIT

ASKER

Thank you all!  This is great information.