是否可以将非控制台Win32应用程序附加到调用cmd shell? [英] Is it possible to attach a non-console Win32 application to the invoking cmd shell?
问题描述
当我有一个Win32非控制台应用程序(AFAIK,Win32应用程序的控制台链接到exe),启动它从控制台 cmd.exe
将立即返回到命令提示符,运行应用程序在后台(oc它可以有一个排序的GUI,甚至打开自己的控制台窗口)
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)
是否可能在非控制台可执行文件检测到它是从cmd.exe启动并附加到启动cmd.exe?
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.)
推荐答案
只需将 ATTACH_PARENT_PROCESS
传给 AttachConsole
。
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.
这篇关于是否可以将非控制台Win32应用程序附加到调用cmd shell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!