Skip to main content

Batch Script Logging

Batch Script Logging

In Batch Script, logging is possible by using the redirection command.

Syntax
example.bat > examplelog.txt 2> exampleerrors.txt

Example

For example, create a file called example.bat and enter the following command in the file:

net statistics /Server

The previous command has an error because the net statistics command option was given incorrectly.

So, if the command with the above example.bat file is run as:

example.bat > examplelog.txt 2> exampleerrors.txt

And you open the file exampleerrors.txt, you will see the following error.

The option /SERVER is unknown.
The syntax of this command is:
NET STATISTICS
[WORKSTATION | SERVER]
More help is available by typing NET HELPMSG 3506.

If you open the file called examplelog.txt, it will show you a log of what commands were executed:

C:\>net statistics /Server