In this article we are going to discuss how to create an executable file in command prompt, that is, how to create a program (script) that runs in CMD. To be able to do this, you will need to have some knowledge of command prompting, so you should know a few commands in this area.
If you don’t know, no problem; you can use the HELP command to help you with the CMD functions. Then, it will be up to you to continue your research to learn more. Let’s go 😉 !
Before we go any further, I hope you know what the command prompt is. For those who don’t know the command prompt, is the Windows command line interpreter (not a game console or anything like that). It’s used to execute commands. The console is a piece of software, or rather a way of using the operating system by means of commands called console codes. This term is very familiar to users of Linux systems.
Well, by default the text is white and there is no transparency but you can customise it. That’s right! This means that you can do everything under the command prompt and even more than you would do with the GUI. But that’s not what we’re going to talk about today, I’ll tell you about that in another article. Let’s move on to what we are interested in here.
As software, here we will use the Windows Notepad, but you can use a text editor that you want like sublime text or vscode. So the first thing to do is to launch your Notepad, then save it in a place you want (and with a name of your choice) but with the extension .cmd.
Look at the location you have chosen, you will see a nice executable file, you can even try by running it
If you find such a message, it is simply because your script has no command yet. So to correct it you just have to type commands in the file and save it. I use the HELP command that I mentioned above. If all goes well, when you run the little script it will start and close suddenly unless you used a different command than mine.
Well, CMD scripts are read by the computer as text files (line by line), that is to say, that the computer reads line by line your script. It tries to execute the tasks it understands and then continues if there is no more task to complete it closes the script.
If you want your script to stay open, use a command that either asks for information input or launches another program and then the script will be closed automatically only after closing the program it launched. Try with the DISKPART command to launch Diskpart, a partition manager (storage media in general) provided by Windows. Here are the captures of my two screens.
Then, if you execute this script it will show the message “You are watching the course code of my script” because the command echo help to display the message. And the command diskpart helps to run the small program “diskpart”
This is just a small script but you can add commands and even a complete program with the same principle. Thanks for reading this article, especially feel free to put any problems or recommendations in the comments. 👍👋