简体   繁体   English

按住命令提示符,直到用户通过关闭按钮将其关闭

[英]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. 我将从C#应用程序中获取命令提示符,以编译一些C ++文件。 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 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. 这将启动cmd.exe,运行指定的命令,并在完成后保持窗口打开。

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. 您可以编写自己的命令提示符程序,该程序充当容器并运行所需的EXE文件。 After running, it can use "cin" (c input) to wait for a keypress and this will stop it closing. 运行后,它可以使用“ cin”(c输入)等待按键,这将停止它的关闭。

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"); 如果要打开命令提示符,则可以调用System.Diagnostics.Process.Start("cmd"); .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM