Open In App

Batch Script – Logging

Last Updated : 02 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Batch Script is a file that consists of various commands which need to be sequentially executed. It is not like coding and is not frequently used, in order to communicate with the OS through a command prompt, the user can use Batch Script. The commands are known as Batch commands.

Logging refers to the process of converting the command line scripts into .log files or text files. The command processor creates real-time activity logs which collect all the information regarding batch commands and statistics.

Syntax 

samplegeeks.bat > samplegeekslog.txt 2> samplegeekserrors.txt

Example

1.) Create a file with the name “samplegeeks.bat”. 

@echo off
echo "HelloGeeks">C:\samplegeeks.txt

 

 

These are the above commands for the execution of the batch files. Please execute in the command line to create a batch file.

2.) Enter the below command in the above-created file.

net statistics /Server

 

The above command will show you an error as the Net Statistics command is given in the wrong way.

3.) If the file got executed with the name “samplegeeks.bat”. 

samplegeeks.bat > samplegeekslog.txt 2> samplegeekserrors.txt

Open the “samplegeekserrors.txt” file to see errors that occurred after executing the command.

 

 

The user will get an error as shown above because of the wrong syntax command execution of net statistics /Server.

The right syntax of the Net Statistics command is given below: 

NET STATISTICS [SERVER/WORKSTATION]

Example:- Net statistics Server

 

The above screenshot is the right syntax output of the Net Statistics command. This command shows the network status and protocols. Users can easily show the level of User Datagram Protocol, Transmission Control Protocol, routing information, etc.

If the user still doesn’t get the error, the user can easily decode the errors with a simple below command.

 NET HELPMSG [numerical network]

 

The above screenshot of cmd commands are examples of the net helpmsg command i.e, 3584 represents the service that did not report an error, and 2182 represents the requested service that has already been started.

Users can open the “samplegeekslog.txt” file which will show activity logs of executed commands.

 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads