Click here to Skip to main content
15,868,016 members
Articles / Programming Languages / C#
Tip/Trick

Batch IDE

Rate me:
Please Sign up or sign in to vote.
4.63/5 (23 votes)
20 Mar 2015CPOL3 min read 80.3K   1.9K   17   30
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)

C#
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:

C#
using Batch_Compiler;

Then, add this code to create a new variable:

C#
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:
C#
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
    C#
    public OpenFileDialog Open = new OpenFileDialog();
  • Save: SaveFileDialog controller
    C#
    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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionBatch IDE Pin
Hrvola10-Jan-18 8:24
Hrvola10-Jan-18 8:24 
AnswerRe: Batch IDE Pin
Alaa Ben Fatma10-Jan-18 8:32
professionalAlaa Ben Fatma10-Jan-18 8:32 
QuestionHow do i set it up? also did you use python to make this? Pin
Member 1338795231-Aug-17 9:20
Member 1338795231-Aug-17 9:20 
AnswerRe: How do i set it up? also did you use python to make this? Pin
Alaa Ben Fatma5-Sep-17 12:08
professionalAlaa Ben Fatma5-Sep-17 12:08 
QuestionIDE? REALLY? Pin
nnnnki4-Aug-15 5:14
nnnnki4-Aug-15 5:14 
AnswerRe: IDE? REALLY? Pin
Alaa Ben Fatma6-Aug-15 6:21
professionalAlaa Ben Fatma6-Aug-15 6:21 
GeneralRe: IDE? REALLY? Pin
nnnnki7-Aug-15 19:29
nnnnki7-Aug-15 19:29 
QuestionBrilliant Pin
mtlabs24-Mar-15 2:07
mtlabs24-Mar-15 2:07 
AnswerRe: Brilliant Pin
Alaa Ben Fatma26-Mar-15 9:48
professionalAlaa Ben Fatma26-Mar-15 9:48 
AnswerRe: Brilliant Pin
nnnnki4-Aug-15 5:18
nnnnki4-Aug-15 5:18 
GeneralRe: Brilliant Pin
Alaa Ben Fatma6-Aug-15 6:22
professionalAlaa Ben Fatma6-Aug-15 6:22 
Generalthanks Pin
joyhen12312323-Mar-15 15:08
joyhen12312323-Mar-15 15:08 
GeneralRe: thanks Pin
Alaa Ben Fatma23-Mar-15 17:29
professionalAlaa Ben Fatma23-Mar-15 17:29 
Suggestionyou must improve the code and add more options Pin
Alberto M.21-Mar-15 0:31
Alberto M.21-Mar-15 0:31 
GeneralRe: you must improve the code and add more options Pin
Alaa Ben Fatma21-Mar-15 3:24
professionalAlaa Ben Fatma21-Mar-15 3:24 
GeneralRe: you must improve the code and add more options Pin
EveryNameIsTakenEvenThisOne21-Mar-15 6:52
professionalEveryNameIsTakenEvenThisOne21-Mar-15 6:52 
GeneralRe: you must improve the code and add more options Pin
Alaa Ben Fatma21-Mar-15 9:18
professionalAlaa Ben Fatma21-Mar-15 9:18 
SuggestionJust and IDE Pin
Alberto M.21-Mar-15 0:30
Alberto M.21-Mar-15 0:30 
QuestionMisleading Pin
EveryNameIsTakenEvenThisOne20-Mar-15 6:50
professionalEveryNameIsTakenEvenThisOne20-Mar-15 6:50 
AnswerRe: Misleading Pin
Alaa Ben Fatma20-Mar-15 13:13
professionalAlaa Ben Fatma20-Mar-15 13:13 
I cannot get the point of this comment .
Well i updated the article the way that it will explain everything clearly to you now , but if there will be something isn't understandable you can ask me , i will be honored ^_^
Thank you .
GeneralRe: Misleading | Edit: Vote of 2 Pin
EveryNameIsTakenEvenThisOne21-Mar-15 6:59
professionalEveryNameIsTakenEvenThisOne21-Mar-15 6:59 
GeneralRe: Misleading | Edit: Vote of 2 Pin
Alaa Ben Fatma21-Mar-15 9:09
professionalAlaa Ben Fatma21-Mar-15 9:09 
GeneralRe: Misleading | Edit: Vote of 2 Pin
EveryNameIsTakenEvenThisOne21-Mar-15 11:53
professionalEveryNameIsTakenEvenThisOne21-Mar-15 11:53 
GeneralRe: Misleading | Edit: Vote of 2 Pin
Alaa Ben Fatma21-Mar-15 14:33
professionalAlaa Ben Fatma21-Mar-15 14:33 
GeneralRe: Misleading | Edit: Vote of 2 Pin
EveryNameIsTakenEvenThisOne21-Mar-15 17:11
professionalEveryNameIsTakenEvenThisOne21-Mar-15 17:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.