This repository was archived by the owner on May 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlauncher.cpp
More file actions
46 lines (38 loc) · 1.53 KB
/
launcher.cpp
File metadata and controls
46 lines (38 loc) · 1.53 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
#include <windows.h>
#include <iostream>
#include <string>
int main() {
// Get the full path of the current executable
char exePath[MAX_PATH];
GetModuleFileName(NULL, exePath, MAX_PATH);
// Extract the directory part from the full path
std::string exeDir(exePath);
size_t pos = exeDir.find_last_of("\\/");
if (pos != std::string::npos) {
exeDir = exeDir.substr(0, pos + 1);
}
// Build command line: assumes Python and script are in the same dir as exe
std::string commandLine = "\"";
commandLine += exeDir + "python_embed\\python.exe\" enviro_tools_gui.py";
STARTUPINFO si = { sizeof(STARTUPINFO) };
PROCESS_INFORMATION pi;
BOOL success = CreateProcess(
NULL, // Application name
(LPSTR)commandLine.c_str(), // Command line
NULL, // Process security attributes
NULL, // Thread security attributes
FALSE, // Inherit handles
CREATE_NEW_CONSOLE, // Creation flags
NULL, // Environment block
exeDir.c_str(), // Working directory (where the script is)
&si, // STARTUPINFO
&pi // PROCESS_INFORMATION
);
if (!success) {
std::cerr << "CreateProcess failed: " << GetLastError() << std::endl;
return 1;
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}