Running an .exe File via Command Prompt

running-an-exe-file-via-command-prompt photo 1

Most of the time our programs work just like we need them to, but every once in a while you have one that is less than cooperative and leaves you looking for a way to fix its ‘attitude’ problem. Today’s SuperUser Q&A post has some great suggestions to help a frustrated reader get the results he needs.

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

running-an-exe-file-via-command-prompt photo 2

The Question

SuperUser reader user418119 wants to find a way to keep a program window open long enough to see the results:

I am trying to run an iteration program. Whenever I click on it, it opens then terminates. When I open the input text file using the program, the iteration completes, then the window instantly closes. How can I:

1. Run it so that the window does not close (and I can see my results)

Or

2. Manage to do the same thing via Command Prompt

I am not super familiar with doing stuff via Command Prompt.

Is there a way to make user418119’s program window stay open long enough to see the results?

The Answer

SuperUser contributors mg30rg, misha256, and Ranayna have the answer for us. First up, mg30rg:

You can create a batch file (.bat) containing two lines. The first one is your application’s command line and the second one is “PAUSE”. It will keep the Command Prompt window open until you press a key or close it using the “X” button. The advantage of this solution is that you can have a separate shortcut to the .bat file so that you can either start your program with or without pausing at the finish.

Followed by the answer from misha256:

This will leave the Command Prompt window open even after MyApp.exe terminates:

  • cmd /K “C:\SomeFolder\MyApp.exe”

You can create a shortcut with the above. This solution works with all console programs and does not require you to go through Command Prompt every time or modify the original .exe file (which you usually cannot).

Incidentally, the /K switch has been around since NT days.

And our final answer from Ranayna:

Another way which is quite useful if the path to the .exe file is a complicated one: Open a Command Prompt window and just drag the .exe file into the window. The full path to the .exe file will be pasted into the Command Prompt window and you just have to press Enter. There is no need to cd into any paths.


Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

More stories

How to Change the Default Fonts in Your Web Browser

While changing your browser’s font may not be the most pressing issue, sometimes it is fun to make a change. That’s why we are going to teach you how to change the default font in Google Chrome, Mozilla Firefox, and Internet Explorer.

What You Need to Know About NVIDIA Optimus

Laptop manufacturers have a choice – they can include onboard graphics for better battery life or discrete graphics hardware for better gaming performance. But wouldn’t it be great if a laptop could have both and intelligently switch between them?

Beginner: How to Create, Manage, and Assign Categories in Outlook 2013

Outlook 2013 lets you assign categories to stuff and customize said categories. The thing about categories is that they’re universal across Outlook, and can you assign each category to a keyboard combination. So, you can categorize email, calendar events, and notes with a couple quick key strokes.

Map Any Key to Any Key on Windows 10, 8, 7, or Vista

If you are tired of the way certain keys on your system work, such as the Caps Lock key, you can re-map them to function as a different key by using a registry hack. But there should be an easier way, right?

Is There an Actual USB Communication Protocol?

Most of us never give much thought to our USB devices, we just plug them in and forget about them. But what if you are the curious type who wants to know more about how USB works? Today’s SuperUser Q&A post has the answers to a curious reader’s questions.

How to Use Parental Controls in OS X to Protect Your Kids

Parental controls are great once you set them up and use them. Busy parents get to breathe a bit easier, and as long as they stay on top of things, even basic parental controls such as those found in OS X, should be more than adequate.

How to Keep Your Minecraft Items When You Die (and Other Clever Tricks)

It happens to even the most cautious explorer: you’re far from home, you die, and all your precious loot is left sitting in a pile far, far away. Tired of losing your loot? No problem. Read on as we show you how to make your Minecraft inventory persist after death (along with some other handy