0% found this document useful (0 votes)
9 views2 pages

OS Lab 2

This document provides instructions for a lab on command prompt scripting and batch files. It defines batch files and scripting languages. It includes examples of creating batch files to run commands like ipconfig and ping, with and without echoing commands. It also shows writing output to a text file. The document covers arithmetic operators that can be used in batch files and provides an example of an if statement. It asks students to write a batch script that computes the product and difference of two numbers, displays the results on screen with a message, and writes the output to a text file.

Uploaded by

Raj Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

OS Lab 2

This document provides instructions for a lab on command prompt scripting and batch files. It defines batch files and scripting languages. It includes examples of creating batch files to run commands like ipconfig and ping, with and without echoing commands. It also shows writing output to a text file. The document covers arithmetic operators that can be used in batch files and provides an example of an if statement. It asks students to write a batch script that computes the product and difference of two numbers, displays the results on screen with a message, and writes the output to a text file.

Uploaded by

Raj Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Department of Information Technology

Faculty of Engineering and Technology


University of Sindh Jamshoro

LAB # 2
BSIT (Part-III)
SENG- 529 Operating Systems
Command Prompt Scripting and Batch Filing
Student Name________________________________ Role No___________________________

LAB OBJECTIVE: To understand and work with windows command prompt scripting and
batch files

TERMINOLOGIES:

Batch files: a computer file containing a list of instructions to be carried out in turn.

Scripting languages: A scripting or script language is a programming language that supports


scripts: programs written for a special run-time environment that automate
the execution of tasks that could alternatively be executed one-by-one by a
human operator. Scripting languages are often interpreted (rather than
compiled)

PRACTICAL EXERCISES

Create a bat file having following code, execute it and check the output

ipconfig /all
ping [Link]
tracert [Link]
PAUSE

Create a bat file having following code, execute it and check the output

Echo off
ipconfig /all
ping [Link]
tracert [Link]
PAUSE

Create a bat file having following code, execute it and check the output written in [Link]
file
ECHO OFF
ipconfig /all >> [Link]
ping [Link] >> [Link]
tracert [Link] >> [Link]

Arithmetic Operators

Operator Description

+ (Addition) Adds values on either side of the operator.

- (Subtraction) Subtracts right-hand operand from left-hand operand.

* Multiplies values on either side of the operator.


(Multiplication)

/ (Division) Divides left-hand operand by right-hand operand.

Divides left-hand operand by right-hand operand and


% (Modulus)
returns remainder.

Arithmetic operation
echo off
set a= 10
set b= 20
set /a c = %a%+%b%
echo addition is (%c%)

If statement Syntax
If Condition
Statements
Try this code
IF NOT DEFINED _example ECHO Value Missing

FOR YOU
Write batch script which:
o Computes product and difference of two number
o Prints the result on screen with appropriate message
o And writes output in text file.

Common questions

Powered by AI

Redirecting command outputs to a text file in batch scripts allows logging of results for future reference, debugging, and auditing. It enables users to save command outputs systematically, assists in preserving output data that may be extensive or quickly scroll off the display, and provides a persistent record of script execution results .

Using 'echo off' in batch scripts suppresses the display of each command on the command prompt as it is being executed, providing a cleaner and more readable output for users. It prevents the command lines from cluttering the terminal, making it easier to focus on the results of the script .

The 'tracert google.com' command in a batch script traces the route packets take to reach the google.com servers. It displays each step of the route, showing routers the packets pass through, providing network diagnostic data that can help identify connectivity issues .

The 'PAUSE' command improves batch file usability by halting script execution and prompting users to press a key to continue. This allows users to review output at their pace and ensures that important information is not missed due to rapid script execution .

The 'IF NOT DEFINED' statement checks for the absence of a particular variable and executes associated commands only if the variable is not defined. This conditional operation is crucial for controlling script flow and ensuring specific blocks of code run only under certain conditions, such as when a variable lacks a value .

Scripting languages facilitate system automation by allowing repetitive tasks to be encoded into scripts that execute without manual intervention, improving efficiency and consistency. They enhance task scheduling, system configuration, and routine maintenance tasks, reducing human error and freeing up time for more complex activities. Benefits include increased productivity, lower operational costs, and improved reliability of automated processes .

Arithmetic operators in batch scripting are used to perform basic mathematical operations like addition, subtraction, multiplication, division, and modulus on numerical values. These operations allow users to perform calculations and store results in variables, facilitating dynamic processing within scripts .

A batch script can log network configurations by redirecting the output of the 'ipconfig /all' command to a text file. For example, a script can include 'ipconfig /all >> networklog.txt' to append the command's output to 'networklog.txt', creating a persistent record of detailed network settings like IP addresses, DNS servers, and more .

Batch files contain a series of commands that are executed by the command interpreter in the operating system. They automate repetitive tasks, allowing users to execute a set of instructions without manually typing each command, increasing efficiency and reducing the likelihood of errors .

Scripting languages are typically interpreted at runtime rather than being compiled beforehand. This means they are translated into machine code line-by-line during execution, allowing for faster development and easier debugging. Compiled languages, however, are translated into machine code prior to execution, making them generally faster and more efficient at runtime but requiring a separate compilation step .

You might also like