Hold the command prompt until user close it from close button
I going to get the command prompt from my C# application to compile some C++ files. Code is like this.
private void button1_Click(object sender, EventArgs e)
{
string filePath = @"C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe";
System.Diagnostics.Process.Start(filePath);
}
But After i click the button it suddenly comes and开发者_如何学JAVA disappear. Even its opening two command prompts. I need to Hold it and only one command prompt should appear. Can some one provide me the necessary codes. Thank you.
You could also do this:
Process.Start("cmd /k cl.exe");
This will launch cmd.exe, running the specified command, and keeping the window open after it's done.
You could change the command from:
<command>
to:
cmd /k <command>
That will cause the command to be run, and then the window will stay open with the command prompt.
The simplest way would probably be something like so:
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd",
Arguments = @"/k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe"""
};
Process.Start(psi);
You could write your own command prompt program that acts as a container and runs the required EXE files. After running, it can use "cin" (c input) to wait for a keypress and this will stop it closing.
You're not opening a command prompt as such, you're just starting a command line app that opens, have nothing to do and then closes.
If you want to open a command prompt you can call System.Diagnostics.Process.Start("cmd");
.
精彩评论