Computer Programming web Web programming Tips

How to create batch file

By Sergey Skudaev

Here you will learn How to create batch file to start an executable in command prompt. Why you want to create batch file. Let imagine that you install Tomcat in "C:\jakarta-tomcat-4.1.29" folder. Then to start Tomcat you have to open command prompt. Usually it opens in "C:\WINDOWS" or "C:\Documents or Settings\< user>" folder. So, you have to type cd.. and press enter to get to C:\> directory, then type cd jakarta-tomcat-4.1.29\bin to get to bin directory. It takes time. Besides, can you remember "jakarta-tomcat-4.1.29"?. I cannot.

It is much easier to open command prompt and type start_tomcat and Tomcat starts. You have to know DOS command to write batch files, so you will learn how to use DOS"

If your MySQL database installed on C: drive and your command prompt Opens in D:\WINDOWS or C:\WINDOWS, each time you want to start MySQL You have to type many command to get to C:\MySQL\bin directory.

In my example, I type C: and press enter to switch to C: drive. I expecting to get to C: root directory, instead I get in directory where my notebook wireless adapter installed, because I executed my adapter to connect to Internet.

batch file - default derictory - command prompt

Now to get to root directory, I have to type cd.. and press enter three times.


C:\Program Files\Linksys\Wireless-B Notebook Adapter>cd..

C:\Program Files\Linksys>cd..

C:\Program Files>cd..


Then to get to MySQL/bin directory, I have to type:

C:\>cd MySQL

C:\MYSQL>cd bin


Then to start MySQL I have to type mysqld for WINDOWS 98, ME or mysqld-nt for WINDOWS 2000.

Then to get to MySQL user interface I have to type MySQL:

batch files - MySQL dir

You can save your time if you create a batch file with following script


cd mysql

cd bin



and save it in D:\WINDOWS directory with the name start_mysql.bat Why in D:\WINDOWS? Because command prompt window opens with the path to this directory (on my PC). On yours it may be different, then you have to save this file in your directory. Then you can open command prompt and type: start_mysql and press enter. MySQL user interface displays. If my Tomcat path is C:\ jakarta-tomcat-4.1.29\bin then to start Tomcat I have to create start_tomcat.bat batch file with following script:


cd jakarta-tomcat-4.1.29

cd bin


The startup.bat batch file that goes with Tomcat distributable is located in bin directory. It will be executed and Tomcat starts. To shut down Tomcat just type shutdown. Because you are already in bin directory shutdown.bat file will be executed and Tomcat shuts down.

My eBooks on


No comments yet.

Add Comment

* Required information
(never displayed)
Smile Sad Huh Laugh Mad Tongue Crying Grin Wink Scared Cool Sleep Blush Unsure Shocked
Enter the third letter of the word castle.
Enter answer:
Enter code:
Notify me of new comments via email.
Remember my form inputs on this computer.
I have read and understand the privacy policy. *
I have read and agree to the terms and conditions. *
Powered by Commentics