How will the prompt tell you when to wait for the exit?

I tried to make Windows command line code in C #. I was wondering how the command window knows when to wait for the process to complete and when not to wait for the called process to exit.

For example, if you enter the Notepad command line, Notepad will start, but you can execute other commands. However, if you open a utility such as more.com, ping.exe, or another utility, it will wait for the program to complete before allowing you to execute another command.

How is it known on the command line when to wait for exit, and how can this behavior be emulated in C #?

+89
c # windows command-prompt
Mar 08 '14 at 19:09
source share
3 answers

If the application is a Win32 graphical application, it will simply start and the command prompt will not wait for exit.

If the application is a console application, it will be launched on the command line, and you will need to wait for it to complete in order to return the command line.

EDIT:

OK You seem to need a technical explanation. If you want to emulate the same function in your application, you can check the IMAGE_OPTIONAL_HEADER EXE files here .

Inside IMAGE_OPTIONAL_HEADER there is:

  WORD Subsystem; 

If SubSystem == 0x02 this means that this is a GUI application.

If SubSystem == 0x03 This means that this is a command line application.

EDIT 2:

If you want to see it in action:

  • Download http://www.ntcore.com/exsuite.php

  • Copy calc.exe or notepad.exe to the desktop

  • Open copied calc.exe file in CFF Explorer

  • Go to Nt Headers -> Additional Headers

  • Change SubSystem from 0x002 to 0x003

  • Save

Now run the new modified calculator, and you will see that it is expected to stop on the command line.

+123
Mar 08 '14 at 19:12
source share

By default, from the command line, run the GUI program in a separate / fork process. However, you can run notepad (or another GUI program) using the command line / shell script:

 start /w notepad.exe 

Thus, the command line / shell script continues only after the completion of the notepad.exe process.

Hope this helps, TW

+7
Mar 09 '14 at 20:45
source share

When you start a new process, a GUI application in this context that actually works outside of the invitation, the invitation will not wait. But if you run a command that fully works under the boundaries of the current instance of the request, it waits.

So, the notepad command just launches the Notepad application and leaves the application under control. While the ipconfig command is working under a domain (this is not an application domain ), there are tips.

Extremely generalize when you use Process.Start in your C # equivalent, don't wait. It will not happen anyway.

+3
Mar 08 '14 at 19:16
source share



All Articles