gpt4 book ai didi

c++ - 控制台提示窗口出现在系统 ("start dir"上,但不出现在系统 ("start ipconfig"上)

转载 作者:可可西里 更新时间:2023-11-01 09:28:35 29 4
gpt4 key购买 nike

我尝试创建一个简单的 UI,它在后台运行命令提示符(但 Windows 控制台不能消失),同时单击每个按钮,resp。

但在此之前,我会尝试类似 system("start dir"); 的方法来查看按钮是否有效。

这是问题所在:当我单击左侧按钮时,Windows 控制台出现并且不退出单元,我将其关闭。但这仅适用于 system("start dir");。如果我将 dir 更改为 ipconfig(或另一个调用函数),Windows 控制台将出现一秒钟然后退出。我尝试了 system("PAUSE");getch(); 等,但它不起作用。

为什么这个命令对 dir 有效,但对另一个命令无效?

Code 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");

只需停止使用 start :)

关于c++ - 控制台提示窗口出现在系统 ("start dir"上,但不出现在系统 ("start ipconfig"上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31162424/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com