Introduction
We have a situation during our GUI application flow, in which we want the command prompt window to execute dynamically. These operations may include executing a script, executing an entire batch file, or even executing a third-party .exe file. In all these scenarios, we need to first call the command prompt. In this article, we are covering five different ways you can call the command prompt for different use cases. Below are those use cases.
We have a situation during our GUI application flow, in which we want the command prompt window to execute dynamically. These operations may include executing a script, executing an entire batch file, or even executing a third-party .exe file. In all these scenarios, we need to first call the command prompt. In this article, we are covering five different ways you can call the command prompt for different use cases. Below are those use cases.
- Open a command prompt window and auto close it once finished
This is one of the most common requirements during setup installation. You want to alert the user that some installation is going on by showing a command window but there's no need of any user interaction to close this window. The window will close itself once its operation has finished. - Open a command prompt window, where the user can interact and the user can close
This is another requirement where opened command prompt window won't close automatically, but user has to close it. If a command window opens like this, the user can interact with it even by adding some inputs. This is a common requirement once you call a .bat file which takes inputs from the user before executing it. So wait for command prompt window to open and wait for user interaction. If you call third party tools like .curl.exe, where it expects multiple input parameters, you need to call the command prompt this way. - Open a command prompt window in hidden mode
Here, you won't see any running command window, but all operations in this mode are hidden. A perfect example is that you may fetch some information from the background, which user doesn't need to know about or interact with. Such on-demand background operations can be achieved by opening command windows in hidden mode. - Call a command prompt with multiple commands
This use case is not related to window mode. If you open a command window either in invisible mode or hidden mode, you will execute multiple commands on it. If you want to run multiple batch processes, then each of the batch calls should able to pass in a single command prompt window call rather than multiple windows. - Open a command prompt with access to its output window
Here no matter how you open the command window and how you execute it, you are not expecting the default output by the command prompt. You want an elaborate output by accessing the standard output stream of the command prompt. This is helpful in most cases if you want to send some logs during execution errors. You will get each command output in your hand and it's so easy to track the success and failure for a lengthy command prompt operation.
Problem Statement
Any C# developer knows how to call a command prompt dynamically. Below is a straightforward call to the command prompt.
- Process p = new Process();
- p.StartInfo.FileName = "cmd.exe";
- p.Start();
Sample Project Details
The sample project uploaded has 5 buttons in it, each for different types of command prompt calls. Please see the image below as you would get one like this, once you're running the sample project.
Below I explain what each button does:

Rajanikant HawaldarPosted May 5, 2019, 11:18 AM
super article
Laxmidhar SahooPosted May 5, 2019, 9:06 AM
Sir Thanks for a fantastic article
abi kaviPosted Aug 15, 2018, 8:01 AM
Nice article
maha lakshmiPosted Aug 15, 2018, 7:56 AM
Thanks for sharing
Guest UserPosted Aug 14, 2018, 10:30 AM
Thanks for sharing