[Final Edit]
a similar SO question combines all of the above and gives you your result C ++ command console without a console
[Edited again]
Erk. sorry i was worried about spawning. I reread your q. and besides an extra window, you are actually trying to get stdout / stderr processes. I just would like to add that for this purpose all my proposals, unfortunately, are not relevant. but I will leave them here for reference.
[Changed]
For no specific reason (except that "open" works for both windows and macs), I use ShellExecute for spawning processes, not for CreateProcess. I will explore this later ... but here is my StartProcess function.
Hidden or smoothed seem to give the same result. the cmd window appears, but it is minimized and never appears on the desktop, which may be your main goal.
#if defined(PLATFORM_WIN32) #include <Windows.h> #include <shellapi.h> #elif defined(PLATFORM_OSX) #include <sys/param.h> #endif namespace LGSysUtils { // ----------------------------------------------------------------------- // pWindow : {Optional} - can be NULL // pOperation : "edit", "explore", "find", "open", "print" // pFile : url, local file to execute // pParameters : {Optional} - can be NULL otherwise a string of args to pass to pFile // pDirectory : {Optional} - set cwd for process // type : kProcessWinNormal, kProcessWinMinimized, kProcessWinMaximized, kProcessHidden // bool StartProcess(void* pWindow, const char* pOperation, const char* pFile, const char* pParameters, const char* pDirectory, LGSysUtils::eProcessWin type) { bool rc = false; #if defined(PLATFORM_WIN32) int showCmd; switch(type) { case kProcessWinMaximized: showCmd = SW_SHOWMAXIMIZED; break; case kProcessWinMinimized: showCmd = SW_SHOWMINIMIZED; break; case kProcessHidden: showCmd = SW_HIDE; break; case kProcessWinNormal: default: showCmd = SW_NORMAL; } int shellRC = (int)ShellExecute(reinterpret_cast<HWND>(pWindow), pOperation,pFile,pParameters,pDirectory,showCmd); //Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise. if( shellRC > 32 ) { rc = true; } #elif defined(PLATFORM_OSX) char cmd[1024]; sprintf(cmd, "%s %s", pOperation, pFile); int sysrc = system( cmd ); dbPrintf("sysrc = %d", sysrc); rc = true; #endif return rc; } }
[and previously mentioned]
If you control the source code of the running application, you can try adding it to the top of your main.cpp (or whatever you called it)
// make this process windowless/aka no console window
You can also pass these parameters directly to the linker. The above is easier to play with various imho build configurations.