#include "pty.h" #include namespace detz::shell { PtyProc::PtyProc() = default; PtyProc::~PtyProc() { if (fd_ >= 0) ::close(fd_); } bool PtyProc::spawn(const std::string& cmd) { FILE* p = ::popen((cmd + " 2>&1").c_str(), "r"); if (!p) return false; char b[1024]; while (std::fgets(b, sizeof b, p)) buf_ += b; ::pclose(p); alive_ = false; fd_ = -1; pid_ = -1; return true; } std::string PtyProc::read_all(int) { std::string o = buf_; buf_.clear(); return o; } int PtyProc::wait() { return 0; } } // namespace detz::shell