Is it possible to attach a non-console Win32 application to the invoking cmd shell?

浪子不回头ぞ 提交于 2020-01-13 09:36:15

问题


When I have a Win32 non-console application (AFAIK, the console-ness of a Win32 app is linked into the exe), starting it from the console cmd.exe will return to the command prompt immediately, running the application "in the background" (o.c. it can have a GUI of sorts, or even open its own console window)

Is it possible in the non-console executable to detect that it was launched from cmd.exe and "attach" it to the launching cmd.exe?

And note that there are various questions/answers related to this, but it seems that this exact approach hasn't been investigated. (Maybe it's not possible like that.)


回答1:


You can do this very easily. Simply pass ATTACH_PARENT_PROCESS to AttachConsole.

Whether or not the end result is sensible or practical is something I could not say. Both processes would read and write to the same console which could get pretty weird.



来源:https://stackoverflow.com/questions/13621542/is-it-possible-to-attach-a-non-console-win32-application-to-the-invoking-cmd-she

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!