Go Back   Gaming Gutter > Non-Gaming > Programming > Tutorials


Tutorials - Looking for programming tutorials to increase your knowledge? Do so here.

» Site Navigation
» Home
» FAQ
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Advertisement
» GG Stuff

Follow us on Twitter!

Get the GG toolbar today (for firefox only)
» Recent Threads
Go to first new post How to Gain UG Access:...
03-01-2009 06:40 AM
by Zombie
Last post by nicki_2036
Today 02:47 AM
1 Replies, 1,879 Views
Go to first new post ~ The Official Hash...
11-06-2009 10:56 AM
by mehike
Last post by _KFC_
Today 01:47 AM
929 Replies, 21,488 Views
Go to first new post HEY, LOOK LOOK!
Yesterday 08:43 PM
Last post by samstah
Today 12:52 AM
18 Replies, 94 Views
Go to first new post ALL YOU WENCHES OUT THERE
Yesterday 04:06 PM
Last post by Crepe
Today 12:46 AM
6 Replies, 60 Views
Go to first new post I should get UG
Yesterday 09:32 PM
Last post by Crepe
Today 12:45 AM
35 Replies, 193 Views
Reply
 
LinkBack Thread Tools Display Modes

 [Batch]Lesson 1: Introduction to Batch Files
Old 08-30-2009, 09:47 PM   #1 (permalink)
Junior Member

Male InfinityCrusher is offline
 
InfinityCrusher's Avatar
 
Join Date: Aug 2009
Location: Vancouver, BC, Canada
Posts: 16
GPoints: 511
iTrader: 0 / 0%
InfinityCrusher Is a New Face in Town
Rep Power: 0
[Batch]Lesson 1: Introduction to Batch Files

Lesson 1: Introduction to Batch Files

I'm sure many of you have seen that little black box with the blinking underscore once or twice in your encounters with Windows. What many of you may not know is that by harnessing the power of batch coding, you're unlocking a massive coding language built into Windows!

Pros of Batch Coding:
  • Easy to learn
  • Does not need a compiler
  • Simple syntax and API
  • Compact
  • Powerful
Cons of Batch Coding:
  • Not as useful compared to languages such as C++
  • Can be dangerous
  • Usually causes suspicion across the internet

With that out of the way, I can continue to teach you the basics of batch coding.

Customary to all intros to coding, I will start off with the ever famous "Hello World!" app.

To begin, you can either use a batch IDE (I recommend Notepad++) or just use Notepad.

The "Echo" Command:

The first command we will learn is the "echo" command. The "echo" command prints the desired word or phrase onto the console.

We will write this into the IDE or Notepad:

Code:
echo Hello World!
Notice how "Hello World!" doesn't need quotation marks around them. This is the beauty and simplicity of batch coding.

You can now save the batch file through notepad as a .bat file or compile with the IDE.

But when you try to execute the file, the black box pops up for half a second and disappears! Why is this?

Well to put it simply, you didn't give the file anything to do after echoing "Hello World!", so it simply exited after finishing its task.

To give the user some input and control over the program, we will use the "pause" command, which will be explained in the next section.

The "Pause" Command:

The "pause" command will be used a lot during your encounter with batch. The command prints the words "Press any key to continue..." on the screen and then waits for your input.

When we add this little snipit to the code, we get the following:

Code:
echo Hello World!
pause
After compiling/saving, and after executing, we get something that looks like this:



But upon examination, we see the commands being executed also printed on the console. Why is this? This is because the commands are not being told to hide themselves from the user.

You will be taught how to hide those commands in the next section.

The "@echo" Command:

In most batch files you see, you will probably see the command "@echo off" dominating the spot of first command. This command simply tells the program to not show what commands are being executed and simply shows the output.

Note: This command is not to be confused with the "echo" command. Without the "@" symbol, the program will just simply print the word "off" on the console.

Inserting this new command, our code should look like this:

Code:
@echo off
echo Hello World!
pause
After compiling/saving, we should get something that looks like this upon execution:



There! Doesn't that look more clean and neat?

Now that you know the basics of batch coding, stay tuned for the next lesson on batch files that can be found here: [Batch]Lesson 2: Improving Your Code
  Reply With Quote
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Powered by vBadvanced CMPS v3.1.0

All times are GMT -7. The time now is 02:57 AM.


vBulletin skin developed by: eXtremepixels
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The contents of this webpage are copyright © 2006-2008 GamingGutter.com. All Rights Reserved.

Page generated in 0.20819998 seconds (100.00% PHP - 0% MySQL) with 21 queries