Close Console After Opening a Program in Batch Script

Close Console After Opening a Program in Batch Script

We can run a program from our batch script using the SET command. As we know, the general format for this purpose is the following.

start "Windows Title" c:\Location\file.exe` or `start "c:\location\" file.exe

But in this way, the console remains open behind.

This article will show how we can close the console or command prompt after opening the program. We will see an example with an explanation for a better understanding.

Close Console After Opening a Program in Batch Script

The general format we will use for this purpose is like the above we discussed. We just put an EXIT keyword at the end.

This keyword will close the command prompt after executing the program specified in the Batch Script. Let’s take a look at our code.

@echo off
START c:\windows\system32\notepad.exe
EXIT

You can see that on the line START c:\windows\system32\notepad.exe, we run the notepad.exe. And lastly, we included the keyword EXIT on our code to close the command prompt after executing the above command.

When you run this code, you will see that the command prompt is closed after running the notepad.exe.

Remember, all methods discussed here are written using Batch Script and will only work in a Windows CMD environment.

MD Aminul Islam avatar MD Aminul Islam avatar

Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.

LinkedIn

Related Article - Batch Program

  • Uninstall Programs in Batch Script