Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Batch IDE

0.00/5 (No votes)
20 Mar 2015 1  
Small tool to write, run batch codes

Introduction

Today's project is somehow special, the way it allows you to learn how to create a simple IDE for Batch language which is related to Windows' commands. It will shows you good tricks to use System.IO & RichTextBox controller tricks too.

Background

As any Windows user, I do use Windows' DOS commands and I did create a lot of .bat applications before.

Honestly, writing batch codes in a Notepad, then saving them as .bat extensions to use them later is a waste of time. That's why I needed to create a simple debugger which contains 1 TextBox (to write the codes) & 1 button (to debug them).

By the time, I developed my own project and it really helped me. Therefore, I want to post my full project here.

Why Should I Create or Use a Project Like This?

Well, let's throw our cards on the table:

  1. This project will solve the problem of wasting time, in other words, you won't need to write and save your batch codes as a .bat file to execute them later because using this project you can execute the codes directly.
  2. How can it help me? Good question, as I said before, you won't waste time anymore by saving your code and executing them after. Also, the environment that this project gives to you is pretty much better than the basic Notepad in my opinion.
  3. The code here is pretty useful - the ways that you will learn about new tricks about richTextBox controller and other Visual Studio tools.

Using the Code

The code which is used in this project is too easy, the most important part here is 'Debugging the code' part. I created a class library which contains the debugging method.

Debug the code class (class library: Batch compiler project ==> Compiler.cs)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
//I used System.IO to manipulate the .bat file
using System.IO;
//I used this system too to run the created file (test.bat) file
using System.Diagnostics;
namespace Batch_Compiler
{
    public  class Compiler
    {
        public static void Debug(string code)
        {
            string path = Path.GetTempPath() + "test.bat" ; //this string called path 
            	//contains the path where the .bat file (which contains the codes will be saved at) .
            File.WriteAllText(path, code); // This code will create the (test.bat) file into Temp folder .
            Process.Start(path); // This Code will run & execute it .
        }
    }
}
  • Variable code will contain the text which is written in the RichTextBox.
  • Variable path will contain the path where the file will be saved at.

Now let's go back to the main project

Import the reference

Right click on "References", result:

Click on "Add Reference..." then this window will appear:

As you can see, we only have created one project beside our main project. So simply click on OK button to import it. Done!

Import the library and the debug method

After we imported our reference (Batch_Compiler) we have to use it, add this code:

using Batch_Compiler;

Then, add this code to create a new variable:

public Batch_Compiler.Compiler Compiler = new Batch_Compiler.Compiler();

Debug (Run the code)

Now let's go to the last part of our project, debugging the code part. All that you have to do is:

  1. Rename your richTextBox controller to "Batch" (just an example)
  2. Double click on Debugging button, then add this code:
Compiler.Debug(Batch.Text);
  • Compiler is the variable which we created from the start
  • Debug is the method that we imported from Batch_Compiler class, it is the method that is used to compile the code (save, then execute it)
  • Batch is our richTextBox controller that we named "Batch" .

Now you can build your project.

Public Variables

  • Open: OpenFileDialog controller
    public OpenFileDialog Open = new OpenFileDialog();
  • Save: SaveFileDialog controller
    public SaveFileDialog Save = new SaveFileDialog();

How to Use the Tool

To use this application as a user, you have to go through these easy steps:

  • Execute it
  • Write your batch code, example:
    @echo off
    Echo Test :: this code to write "Test" 
    Pause
  • Debug it using the yellow button .

That's it.

What Can I do Using This Software?

  • You can use the software to write your own batch codes.
  • You can save them as Batch file or Text file.
  • You can debug the batch code directly without the need to save the code into .bat file.
  • You can save the batch codes into a .bat file to use it later (use the green button : )

Screenshots

Points of Interest

It is so funny how my friends kept asking for the source code of this project and I kept ignoring them (acting). It will be a good surprise for everyone (I hope), but it is great to see a lot of people who want to learn.

History

  • March 19, 2015: First upload

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here