命令提示符如何知道何时等待退出? [英] How does the command prompt know when to wait for exit?
问题描述
我试图用C#对Windows命令提示符进行重新编码。我想知道命令提示符如何知道何时等待进程开始退出,以及何时不等待调用的进程退出。
I was attempting to do a Windows command prompt re-code in C#. I was wondering how the command prompt knows when to wait for the process started to exit, and when not to wait for the called process to exit.
例如,如果您在命令提示符下输入记事本,记事本将启动,但您仍然可以执行其他命令。但是,如果您打开诸如more.com,ping.exe或其他实用程序的实用程序,它将等待执行程序完成后才允许您执行另一个命令。
For example, if you type in the command prompt "notepad", Notepad will launch, but you can still execute other commands. However, if you open a utility such as more.com, ping.exe, or another utility, it will wait for the executing program to finish before letting you execute another command.
命令提示符如何知道何时等待退出,以及如何在C#中模拟此行为?
How does the command prompt know when to wait for exit, and how can this behavior be emulated in C#?
推荐答案
如果该应用程序是Win32 GUI应用程序,它将仅运行并且命令提示符不会等待其退出。
If the application is a Win32 GUI application, it will just run and command prompt won't wait for it to exit.
如果该应用程序是控制台应用程序,它将运行在命令提示符下,您将需要等待它完成才能返回命令提示符。
If the application is a console application, it will run in the command prompt and you'll need to wait for it to finish to get the command prompt back.
编辑:
确定。看来您需要技术说明。如果要在应用程序中模拟相同的功能,则可以检查 IMAGE_OPTIONAL_HEADER
EXE文件此处。
OK. It seems you need technical explanation. If you want to emulate the same feature in your application, you can check IMAGE_OPTIONAL_HEADER
of EXE files here.
内部 IMAGE_OPTIONAL_HEADER
,有:
WORD Subsystem;
如果SubSystem == 0x02
一个GUI应用程序。
If SubSystem == 0x02
it means it's a GUI application.
如果SubSystem == 0x03
,则表示它是命令提示符应用程序。
If SubSystem == 0x03
it means it's a command prompt app.
编辑2:
如果您想查看它的作用:
If you want to see it in action:
将calc.exe或notepad.exe复制到桌面上
Copy calc.exe or notepad.exe to your desktop
在CFF Explorer中打开复制的calc.exe
Open copied calc.exe in CFF Explorer
导航至Nt标头->可选标头
Navigate to Nt Headers -> Optional Headers
将子系统从0x002更改为0x003
Change SubSystem from 0x002 to 0x003
保存它
现在运行新修改的calc,您将看到命令提示符等待其终止。
Now run the new modified calc and you'll see the command prompt wait for it to be terminated.
这篇关于命令提示符如何知道何时等待退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!