to launch an exe, I have wrote the CreateProcess of this thread How do I open an .exe from another C++ .exe?
this works but if my first program end the cmd will close and i want to keep my launched program running
my code looks like that
void Client::StartServer(){
//init process structures
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
// get working directory
char tmp[512];
GetModuleFileName(NULL, tmp, 512);
stringstream sstmp;
string stmp;
sstmp << tmp;
stmp = sstmp.str();
//remove name.exe from path
while(stmp.back() != '\\'){
stmp.pop_back();
}
//launch
sstmp.str("");
sstmp << stmp << "Sim_Server.exe";
cout << "start : " << sstmp.str() << " end "<< endl;
LPCTSTR path = sstmp.str().c_str();
if( !CreateProcess(path,NULL,NULL,NULL,false,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi) ){
throw runtime_error("unable to launch server");
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}