The Hallow Life

Full Version: The Basics
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
to start off there is the @echo off/on
and there is echo
and pause

so here is an example
Quote:@echo off
echo Hello This is a test
pause

type this in notepad and save as test.bat
launch it
it will look like this


Quote:Hello This is a test
Press any key to continue...

Again open notepad and write:

Quote:@echo on
echo Hello This is a test
pause

and save it on the desktop as test2.bat
launch it , it will look like this
>
Quote:C:\Documents and Settings\User\Desktop>echo Hello This is a test
Hello This is a test
C:\Documents and Settings\User\Desktop>pause
Press any key to continue

So for the explanation
@echo off/on:
if you put @echo on it will show the directory as you just saw
if you put @echo off it will just show the words with no directories
so its best to use @echo off

echo:
If you want to type a simple phrase just type in echo and something in this case echo Hello This is a test
which will show Hello This is a test

pause
pause will pause the batch file,if you press a key the batch will continue in this case it will exit because there is no more left
so try this

Quote:@echo off
echo Hello This is a test
pause
echo I am testing pause
pause

This will show

Quote:Hello This is a test
Press Any Key To Continue...
(when you press a key it will show)
I am testing a pause
Press Any key to continue..

so that convers the pause command

Now some more commands
there is msg *
and there is cls

open notepad and write:


Quote:@echo off
echo Hello This is a test
pause
cls
echo I am testing pause
msg * The End
pause


and save as test3.bat

This will show

Quote:Hello This is a test
Press Any Key To Continue...
(when you press a key it will show)
cls
(the page will clear)
I am testing a pause
(a pop-up will show saying The End)
Press Any key to continue..

So .. cls will just clear the screen
and msg * will bring up a pop-upBig Grin

other commands are REM and goto and start
so create a folder name it Test
put any picture inside and name it testpic
open notepad and type

Quote:@echo off
echo Testing start and rem
rem title Test
start testpic.jpg (or any other extension)
pause

and save it inside the new folder as test4.bat

launch it , it will show:

Quote:Testing start and rem
Press Any Key To Continue
(and the picture will launch)

so start will launch any file
and rem is a remark.. which wont show in the bat file when running

now the goto and set and if

type this inside notepad

Quote:@echo off
echo This is a test
echo If you want to do math type 1 and press enter
echo If you want to see a picture type 2 and press enter
set /p option=
if '%option%'=='1' goto :math
if '%option%'=='2' start testpic.jpg (or any extension)

:math
echo 2+2
pause

and save it inside the new folder

this will show

Quote:This is a test
If you want to do math type 1 and press enter
if you want to see a picture type 2 and press enter
(here you can type 1 or 2 and press enter)
(if you press 2 and Enter the picture will load)
(if you press 1 and enter this will show up):
2+2
Press any key to continue...

so goto will go to a Label or a Part of the file
when you put :Math
a new label will be named Math and when you put goto :math
the batch will go to :math

set
the set option will set something Big Grin.. here its going to set :choice
the set is , in some options followed by if
so if I type 1 in this example
the "choice" will be 1 .. and it will go to :math because we put
if '%choice%'=='1' goto :math
so if we put 1 the choice will be 1 therefore it will goto :math

anyway those are the basics..
stay on hackforums.net and wait for more batch tutorials.. next time it will be more advanced
Reference URL's