2016-05-31 03:58:58 +00:00
|
|
|
#pragma once
|
2016-05-19 14:41:06 +00:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "exception.hpp"
|
|
|
|
#include "utils/proc.hpp"
|
|
|
|
|
2016-05-31 03:58:58 +00:00
|
|
|
DefineBaseException(CommandException);
|
2016-05-19 14:41:06 +00:00
|
|
|
|
|
|
|
class Command
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
std::string cmd;
|
|
|
|
|
2016-06-14 11:17:03 +00:00
|
|
|
int fd_stdout[2];
|
|
|
|
int fd_stdin[2];
|
2016-05-19 14:41:06 +00:00
|
|
|
|
|
|
|
pid_t fork_pid;
|
|
|
|
int fork_status;
|
|
|
|
|
|
|
|
public:
|
2016-05-31 03:58:58 +00:00
|
|
|
Command(const std::string& cmd, int stdout[2] = nullptr, int stdin[2] = nullptr);
|
|
|
|
~Command();
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-05-31 03:58:58 +00:00
|
|
|
int exec(bool wait_for_completion = true);
|
|
|
|
int wait();
|
2016-05-19 14:41:06 +00:00
|
|
|
|
|
|
|
void tail(std::function<void(std::string)> callback);
|
|
|
|
int writeline(const std::string& data);
|
|
|
|
|
|
|
|
int get_stdout(int);
|
2016-05-31 03:58:58 +00:00
|
|
|
// int get_stdin(int);
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-06-14 10:14:29 +00:00
|
|
|
pid_t get_pid();
|
|
|
|
bool is_running();
|
|
|
|
int get_exit_status();
|
2016-05-19 14:41:06 +00:00
|
|
|
};
|