Here is a windows function to suit your needs. It is based on code from FAQ: How do I run a program from within a program.
Code:
#include <windows.h>
#include <cstdio>
using namespace std;
BOOL SpawnInNewConsole(LPCTSTR szPath)
{
STARTUPINFO si = { 0 }; // Defines how to start the program
PROCESS_INFORMATION pi; // Gives info on the thread and..
// ..process for the new process
si.cb = sizeof(si); // Must set size of structure
BOOL bRet = CreateProcess(
szPath, // Path to executable file
NULL, // Command string - not needed here
NULL, // Process handle not inherited
NULL, // Thread handle not inherited
FALSE, // No inheritance of handles
CREATE_NEW_CONSOLE, // Create a new console for program
NULL, // Same environment block as this prog
NULL, // Current directory - no separate path
&si, // Pointer to STARTUPINFO
&pi); // Pointer to PROCESS_INFORMATION
if(bRet)
{
CloseHandle(pi.hThread); // Close handle to thread
CloseHandle(pi.hProcess); // Close handle to process
}
return bRet;
}
int main(void)
{
if (!SpawnInNewConsole("ServerMain.exe"))
{
printf("Failed to launch program!");
}
return 0;
}