Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.)

like image 849
Martin Ba Avatar asked Nov 29 '12 08:11

Martin Ba


1 Answers

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.

like image 82
David Heffernan Avatar answered Oct 18 '22 08:10

David Heffernan