VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
Execute.hpp
1#pragma once
2#include <iostream>
3#include <string>
4#include <cstdio>
5#include <functional>
6
7#ifdef _WIN32
8 #define POPEN_FUNC _popen
9 #define PCLOSE_FUNC _pclose
10#else
11 #define POPEN_FUNC popen
12 #define PCLOSE_FUNC pclose
13 #include <unistd.h>
14#endif
15
19inline void executeCommandRealTime(const std::string& cmd, std::function<void(const std::string&)> lineCallback) {
20 FILE* pipe = POPEN_FUNC(cmd.c_str(), "r");
21
22 if (!pipe) {
23 lineCallback("ERROR: Could not run command: " + cmd);
24 return;
25 }
26
27 setbuf(pipe, NULL);
28 char buffer[512];
29 while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
30 std::string line = buffer;
31 lineCallback(line);
32 std::fflush(stdout);
33 }
34
35 PCLOSE_FUNC(pipe);
36}