Command Prompt Lesson 1

by Batch4Life in Circuits > Computers

4815 Views, 22 Favorites, 0 Comments

Command Prompt Lesson 1

Intro.png

Welcome to my first instructable ever. My name is Batch4Life and I will be making instructables on how to write batch files. I will try my best to go in depth because learning how to write batch files for me was tough because it is a lot of learning by yourself. I will start from the bone basics and teach from there so you have a strong foundation.

Starting Out

Step 1.png

You need to open notepad.exe. You can open notepad by right clicking on your desktop and then clicking New -> New Text Document. Set the name as "Lesson 1"

Build the Program

Step 2.png

@echo off

This is the first thing you want to put type in the document. It will be used at the top of almost everything you will ever make. What is does it makes it so that the directory of where the command is being executed from is hidden or made invisible. This makes the whole thing look a lot cleaner.

Color

Step 3.png

@echo off

color a

The default color for windows command prompt is white text on a black background. color a changes the color to a light green text. I almost always change the color in my files to make them more visible to read. For a list of colors you can choose from refer to the picture above. The picture also has additional instructions to change the background.

Printing Text

Step 4.png

@echo off

color a

echo Hello!

The line "echo Hello!" prints the text "Hello!" on the command line. It will be in which ever color that you specified before. You can make it print what ever you want as long as you have a space after echo. To print a completely blank line, you type "echo." Ex.

@echo off

color a

echo 1

echo.

echo 2

Would have the output

1

(Blank line)

2

Pausing

Step 5.png

@echo off

color a

echo Hello!

pause

The line that has "pause" on it pauses the batch file and outputs the line "Press any key to continue..." This is so you can see what you printed without it just instantly closing on you. To make the "Press any key to continue..." invisible to make a clean look you add a ">nul" to the back. It would look like this...

@echo off

color a

echo Hello!

pause>nul

Finish!

Intro.png

@echo off

color a

echo Hello!

pause>nul

You have now written your first batch file. I am sure it took me a lot longer to write this then it did for you to read it so I hope you enjoyed. I will be creating future lessons if this one gets noticed.

-Batch4Life