Sie sind auf Seite 1von 34

1

Visit our Site :www.theprominence.org

Presents,

By Shantanu.Vishwanadha
Co-Founder & Technologist
TheProminence
4

Contents
1.

2.
3.
4.
5.
6.

About the Author


What is batch programming ?
File Extension
Creating 1st Basic Program in Batch
Programming.
Uses of Commands
At the End

About the AuthorShantanu.Vishwanadha

Shantanu Vishwanadha is the Co-founder and


Technologist of theprominence.org. Shantanu Cofounded this Non-Profit Organisation in the year
2014.
Basically Shantanu is a Web designer , Computer
Programmer , Technologist , Gadget Lover ,
Scientific-geek , a Blogger and Die hard American
Idiot fan and Amateur Photographer.

P.T.O

Shantanu was in class 9th when he founded this Organisation.


Shantanu is Currently Studying in Class 10th.
Shantanu is also managing a multi-Niche blog named ITVizkids
http://itvizkids.in

Shantanu has completed his expert courses in CSS , PHP , C++


, Batch ,HTML , JAVA and JAVASCRIPT
You Can Connect Shantanu on Twitter :- @shantanu_vizkid
You can Drop Shantanu a mail :mailvishwanadha@gmail.com
8

About the Book!


This is a Free Ebook Only available at
http://babagers.theprominence.org
and http://itvizkids.in
This Ebook is Open Source.
This is the First Version of this Book, More Versions will be
released very Soon.
Keep Visiting IT-Vizkids and Babagers , for latest updates of
this ebook.

Note:- you can Get Ebook only when you Enroll or signup
for the batch programming Course at
babagers.theprominence.org
9

WHAT IS
BATCH
PROGRAMMING
?

10

What is Batch Programming ?


In DOS, OS/2, and also Microsoft Windows, batch
file is the name given to a type of script file, a text
file containing a series of commands to be
executed by the command interpreter.
A batch file may contain any command the
interpreter accepts interactively at the command
prompt. A batch file may also have constructs (IF,
GOTO, Labels, CALL, etc.) that enable conditional
branching and looping within the batch file.
11

Similar to job control language and other systems on


mainframe and minicomputer systems, batch files were
added to ease the work required for certain regular
tasks by allowing the user to set up a script to
automate them. When a batch file is run, the shell
program (usually COMMAND.COM or cmd.exe) reads
the file and executes its commands, normally line-byline.Unix-like operating systems (such as Linux) have a
similar, but more flexible, type of file called a shell
script.
12

The filename extension .bat was used in DOS, and the


Windows 9x family of operating systems. The Microsoft
Windows NT-family of operating systems and OS/2
added .cmd. Batch files for other environments may
have different extensions, e.g. .btm in 4DOS, 4OS2 and
4NT related shells.
There have been changes to the detailed handling of
batch files; some of the detail in this article is
applicable to all batch files, while other details apply
only to certain versions
13

DOS
In MS-DOS, a batch file can be started from the command line
by typing its name followed by any required parameters and
pressing the "enter" key. When MS-DOS loads, the file
AUTOEXEC.BAT is automatically executed, so any commands
that need to be run to set up the MS-DOS environment for
use could be placed in this file. Computer users would have
the autoexec file set up the system date and time, initialize
the MS-DOS environment, load any resident programs or
device drivers, or initialize network connections and
assignments.

14

In MS-DOS, the extension ".BAT" identified a


file containing commands which could be
executed by the command interpreter
COMMAND.COM line by line as if it was a list
of commands to be entered, with some extra
batch-file-specific commands for basic
programming functionality, including a GOTO
command for changing flow of line execution.
15

Windows!
Early Windows
Microsoft Windows was introduced in 1985 as a
GUI-based alternative to text-based operating
systems and was designed to run on MS-DOS. In
order to start it, the WIN command was used and
could be added to the end of the AUTOEXEC.BAT
file to allow automatic loading of Windows. In the
earlier versions one could run a .bat type file
from Windows in the MS-DOS Prompt.
16

Windows was run from MS-DOS and used


COMMAND.COM to run .bat files on the
following operating systems:

Windows 1, 2 and 3.
Windows 95 and 98.
Windows ME (access to real mode MS-DOS
was restricted).
OS/2

17

Microsoft released a version of cmd.exe for Windows


9x and ME called WIN95CMD to allow users of older
versions of Windows to use certain cmd.exe-style batch
files.
As of Windows 8, cmd.exe is the normal command
interpreter for batch files; the older COMMAND.COM
can be run from within a cmd.exe window in 32-bit
versions of Windows able to run 16-bit program
OS/2's batch file interpreter also supports an EXTPROC
command. This passes the batch file to the program
named on the EXTPROC file as a data file. The named
program can be a script file; this is similar to the #!
mechanism.

Source :- wikipedia
18

File Extensions
19

File Extensions
Filename extensions
.bat: The first filename extension used by
Microsoft for batch files. This extension runs
with MS-DOS and all versions of Windows,
under COMMAND.COM or cmd.exe, despite
the different ways the two command
interpreters execute batch files.

20

.cmd: Used for batch files in Windows NT family


and sent to cmd.exe for interpretation.
COMMAND.COM does not recognize this
filename extension, cmd.exe scripts are not
executed in the wrong Windows environment by
mistake. In addition, "set", "path", "assoc" and
"prompt" commands, when executed from a .bat
file, alter the value of the "errorlevel" variable
only upon an error, whereas from within a .cmd
file, they would affect errorlevel even when
returning without an error. It is also used by
IBM's OS/2 for batch files.
21

.btm: The extension used by 4DOS and 4NT.


The scripts that run on 4DOS and 4NT are
faster, especially with longer ones, as the
script is loaded entirely ready for execution,
rather than line-by-line

22

Creating Your
First Batch
Program.
23

Creating your First Program in Batch


A batch file contains a series of DOS commands, and is
commonly written to automate frequently performed tasks.
Instead of typing the same commands over and over, you can
simply double-click the batch file. Writing a batch file is easier
than it looks; the difficult part is making sure that everything
happens in the right order. Well-made batch files can save you
a lot of time over the long run, especially if you deal in
repetitive tasks.

24

Open Notepad. Notepad allows you to create code as a


text file and then save it when you're done as a batch file.
You can open Notepad by clicking Start Programs
Accessories Notepad. You can also enter notepad into
the Run box.
Learn some basic batch commands. Batch files run a series of ODS commands, so the
commands that you can use are similar to DOS commands. Some of the more
important ones include:ECHO - Displays text on the screen
@ECHO OFF - Hides the text that is normally output
START - Run a file with it's default application
REM - Inserts a comment line in the program
MKDIR/RMDIR - Create and remove directories
DEL - Deletes a file or files
COPY - Copy a file or files
XCOPY - Allows you to copy files with extra options
FOR/IN/DO - This command lets you specify files.

25

(3) Now , Open Notepad and Write @echo off in the First
line.
(4) Next , Write Echo and hello world ( instead of hello
world , you can write anything you want )
(5) Write Pause your Notepad will be somewhat like this :-

26

After This , Save the File as .bat (look at the


image for reference ) The File extension
should be .bat

27

Now Run the Program :As We have Wrote hello World. Its Printed and
executed. This is the Basic Program in batch.

28

Now Press Enter to Finish.


Lets know more about each of the command
used in the Example.

29

Meanings of
Commands we
Used in the
Program
30

Commands Used
1. @echo off :- putting a @ at the start of a line
prevents the command on that line from
being shown (echoed) on the screen. '@echo
off' basically means that you give a "silent"
command (with the @) to not show any
future commands echoed on the screen
anymore - without it, any command executed
in a batch file would be shown on the screen.
31

Echo :- using 'echo' in a batch file allow you to


print a custom message on the screen. e.g.
'echo Hello there!' would print the text "Hello
there!" on the screen.
Pause :- pauses the command and the process
at the last stage.

32

At the End!
Now we have reached the end of this ebook.
In this Ebook , we have tried to teach you the
basics of Batch Programming..
Keep looking out for latest updates and more
versions of this Ebook.
Basic Batch Programming-1 Ends Here.
Thank you for Downloading.
33

Thank
You
If you like this book , please take a Minute and mail us a feedback.
Our mail ID is tech@theprominence.org
34

Das könnte Ihnen auch gefallen