Reputation: 38766
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
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