控制台提示窗口出现在系统(“开始目录”),但不是在系统(“开始IPCONFIG”)

我尝试创build一个简单的UI,在后台运行命令提示符(但是Windows控制台一定不能消失),同时点击每个button,

但之前,我尝试了一些像system("start dir"); 看button是否工作。

这里是问题:当我点击左边的button,出现窗口控制台,不要退出单元我closures它。 但这只适用于system("start dir"); 。 如果我改变目录ipconfig (或另一个调用函数),Windows控制台将出现一秒钟,并退出。 我尝试了一些像system("PAUSE");getch(); 等等,但它不工作。

为什么这个命令与dir一起工作,而不是与另一个命令?

码UI

DIR和IPCONFIG之间有一个根本的区别,DIR命令被内置到命令处理器(又名shell)中,IPCONFIG是一个单独的程序存储在c:\ windows \ system32中。

当你输入START /? 在命令行中,你可以看到为什么它以不同的方式对待它们:

 If it is an internal cmd command or a batch file then the command processor is run with the /K switch to cmd.exe. This means that the window will remain after the command has been run. If it is not an internal cmd command or batch file then it is a program and will run as either a windowed application or a console application. 

另一种方法是让命令处理器执行命令,然后退出。 你用/ c选项做:

  system("cmd.exe /c dir"); 

或者更简单,因为system()会自动将作业传递给命令处理器:

  system("dir"); 

只要停止使用开始:)