Martin Ba
Martin Ba

Reputation: 38766

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

Upvotes: 7

Views: 1014

Answers (1)

David Heffernan
David Heffernan

Reputation: 612854

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.

Upvotes: 6

Related Questions