You've mix up terms. The "Windows Console" is not a "cmd.exe", but special "service" which implemented, for example of Win7, with "conhost.exe".
When you start any console application (does not matter cmd, powershell, or your own app) windows starts it in special environment, which may have visible console window. But it is always internal Windows console.
But! Console emulators may grab this window, hide real console and display their own emulated surface.
For example, you may start ConEmu with special switches (described on SU, link in comment) and its done.
Default terminal replacement
ConEmu has a feature named Default Terminal
. If you enable this feature you will get seamless starting up your application from Visual Studio in the ConEmu terminal. The idea is hooking CreateProcess in source application (explorer.exe
, vcexpress.exe
and so on, delimit them with |
in the settings). Read more about that feature in the project wiki.
You may choose to use existing ConEmu instance or to run new window for your application. And ConEmu can show Press Enter or Esc to close console...
message on the console after your application exits (the Always
radio). No need to add readline
at the end of your program anymore to see the output.
Changing your application code
Because it is your own program, you may add, for example, following lines to the head of your main
function
C++ example
#ifdef _DEBUG
if (IsDebuggerPresent())
{
STARTUPINFO si = {sizeof(si)}; PROCESS_INFORMATION pi = {};
if (CreateProcess(NULL,
_T("\"C:\\Program Files\\ConEmu\\ConEmu\\ConEmuC.exe\" /AUTOATTACH"),
NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
{ CloseHandle(pi.hProcess); CloseHandle(pi.hThread); }
}
#endif
C# example
#if DEBUG
ProcessStartInfo pi = new ProcessStartInfo(@"C:\Program Files\ConEmu\ConEmu\ConEmuC.exe", "/AUTOATTACH");
pi.CreateNoWindow = false;
pi.UseShellExecute = false;
Console.WriteLine("Press Enter after attach succeeded");
Process.Start(pi);
Console.ReadLine();
#endif