Files
tai/taicpp/src/shell/pty.cpp
T
2026-10-24 06:41:22 +02:00

16 lines
540 B
C++

#include "pty.h"
#include <cstdio>
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