-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
55 lines (47 loc) · 1.96 KB
/
main.cpp
File metadata and controls
55 lines (47 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Launcher: starts server, gateway, and client in separate console windows.
* When run from IDE as the main target, opens three windows.
* Run server, gateway, or client target individually for a single console.
*/
#include <cstdlib>
#include <string>
#include <iostream>
#if defined(_WIN32) || defined(_WIN64)
#define EXE_EXT ".exe"
#else
#define EXE_EXT ""
#endif
int main(int argc, char** argv)
{
// Paths relative to current working directory (build directory when run from IDE)
std::string server_exe = "server/server" EXE_EXT;
std::string gateway_exe = "gateway/gateway" EXE_EXT;
std::string client_exe = "client/client" EXE_EXT;
#if defined(_WIN32) || defined(_WIN64)
// On Windows, use "start" to open each in a new console window
std::cout << "Starting Server, Gateway, and Client in separate windows..." << std::endl;
auto runInNewConsole = [](const std::string& title, const std::string& exe) {
std::string cmd = "start \"" + title + "\" \"" + exe + "\"";
int r = std::system(cmd.c_str());
if (r != 0) {
std::cerr << "Failed to start " << title << " (" << exe << ")" << std::endl;
return false;
}
return true;
};
if (!runInNewConsole("Server", server_exe)) return 1;
if (!runInNewConsole("Gateway", gateway_exe)) return 1;
if (!runInNewConsole("Client", client_exe)) return 1;
std::cout << "All three applications started. Close this window or press Enter to exit launcher." << std::endl;
std::cin.get();
#else
// On Unix, run in background (or use xterm/gnome-terminal for separate windows)
std::cout << "Starting Server in background..." << std::endl;
std::system(("./" + server_exe + " &").c_str());
std::cout << "Starting Gateway in background..." << std::endl;
std::system(("./" + gateway_exe + " &").c_str());
std::cout << "Starting Client (foreground)..." << std::endl;
std::system(("./" + client_exe).c_str());
#endif
return 0;
}