From f7efa11cdddd32ff6525603b10cc5782b1a613c2 Mon Sep 17 00:00:00 2001 From: "U-olece-PC\\olece" Date: Thu, 20 Aug 2015 15:09:31 +0200 Subject: [PATCH] terminal now works on Cygwin. --- src/terminal.cc | 50 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/terminal.cc b/src/terminal.cc index d47b9be..4df8e24 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -11,7 +11,7 @@ using namespace std; //TODO: remove //TODO: Windows... //A working implementation of popen3, with all pipes getting closed properly. //TODO: Eidheim is going to publish this one on his github, along with example uses -pid_t popen3(const char *command, int &stdin, int &stdout, int &stderr) { +pid_t popen3(const char *command, int &stdin_fd, int &stdout_fd, int &stderr_fd) { pid_t pid; int p_stdin[2], p_stdout[2], p_stderr[2]; @@ -56,9 +56,9 @@ pid_t popen3(const char *command, int &stdin, int &stdout, int &stderr) { close(p_stdout[1]); close(p_stderr[1]); - stdin = p_stdin[1]; - stdout = p_stdout[0]; - stderr = p_stderr[0]; + stdin_fd = p_stdin[1]; + stdout_fd = p_stdout[0]; + stderr_fd = p_stderr[0]; return pid; } @@ -145,18 +145,18 @@ int Terminal::execute(const std::string &command, const boost::filesystem::path else cd_path_and_command=command; - int stdin, stdout, stderr; - auto pid=popen3(cd_path_and_command.c_str(), stdin, stdout, stderr); + int stdin_fd, stdout_fd, stderr_fd; + auto pid=popen3(cd_path_and_command.c_str(), stdin_fd, stdout_fd, stderr_fd); if (pid<=0) { async_print("Error: Failed to run command: " + command + "\n"); return -1; } else { - std::thread stderr_thread([this, stderr](){ + std::thread stderr_thread([this, stderr_fd](){ char buffer[1024]; ssize_t n; - while ((n=read(stderr, buffer, 1024)) > 0) { + while ((n=read(stderr_fd, buffer, 1024)) > 0) { std::string message; for(ssize_t c=0;c 0) { + while ((n=read(stdout_fd, buffer, 1024)) > 0) { std::string message; for(ssize_t c=0;c 0) { + while ((n=read(stderr_fd, buffer, 1024)) > 0) { std::string message; for(ssize_t c=0;c 0) { + while ((n=read(stdout_fd, buffer, 1024)) > 0) { std::string message; for(ssize_t c=0;c