Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide batch output

I am putting the finishing touches to a batch script that transfers the contents of a locally edited web site to the internet.

The script opens in a console window, and outputs quite a lot of stuff the administrator needs to see in case something goes wrong. In that case, though, the output is being sent as E-Mail, so there is no need to display the output and confuse the user who runs the update unnecessarily. I need to display only a few lines (say, "starting synchronisation..." and "syncrhonisation complete").

Can anybody think of a way to stop output in a batch script? Kind of a total "echo off"?

A simple

my_batch_file > nul 

won't cut it, because as I said, a few things I need to show.

like image 706
Pekka Avatar asked Jan 11 '10 20:01

Pekka


People also ask

How do I make a batch file run silently?

1] Hidden Start or HStartDrag, and drop the batch file onto the interface. Choose options including hiding console windows, UAC, and so on. You can also test it using test mode. You can also add command-line options if needed.

What does %% mean in batch?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

What does @echo off mean in CMD?

echo off. When echo is turned off, the command prompt doesn't appear in the Command Prompt window. To display the command prompt again, type echo on. To prevent all commands in a batch file (including the echo off command) from displaying on the screen, on the first line of the batch file type: @echo off.


1 Answers

Windows actually does have the notion of stdout and stderr. Here's an example:

test.bat:

@echo off echo verbose stuff 1 echo verbose stuff 2 echo verbose stuff 3 echo important stuff! >&2 echo verbose stuff 4 

If you run it as 'test.bat' you'll get the full output. If you run it as 'test.bat >nul' then you'll only get the 'important' output (anything redirected to stderr, with the >&2)

like image 157
davr Avatar answered Oct 07 '22 01:10

davr