MangoHud/src/shell.h

36 lines
615 B
C
Raw Permalink Normal View History

#pragma once
#include <fcntl.h>
#include <unistd.h>
#include <cstring>
2024-04-04 23:42:49 +00:00
#ifdef __linux__
#include <sys/wait.h>
2024-04-04 23:39:09 +00:00
#endif
#include <string>
#include <memory>
class Shell {
private:
int to_shell[2];
int from_shell[2];
pid_t shell_pid;
bool success;
2024-04-04 23:42:49 +00:00
#ifdef __linux__
void setNonBlocking(int fd) {
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
2024-04-04 23:39:09 +00:00
#endif
2024-04-08 23:48:45 +00:00
void writeCommand(const std::string& command);
std::string readOutput();
public:
Shell();
~Shell();
std::string exec(std::string cmd);
};
extern std::unique_ptr<Shell> shell;