diff options
Diffstat (limited to 'project2/processes/processStream.cpp')
-rw-r--r-- | project2/processes/processStream.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/project2/processes/processStream.cpp b/project2/processes/processStream.cpp index 13c2555..1a853e4 100644 --- a/project2/processes/processStream.cpp +++ b/project2/processes/processStream.cpp @@ -1,5 +1,6 @@ #include "iHaveParameters.h" #include "scriptLoader.h" +#include "scopeObject.h" #include "scripts.h" #include "stream.h" #include <exception> @@ -29,8 +30,13 @@ class ProcessStream : public Stream, IHaveParameters { callProc[pidx++] = p.second(); } callProc[pidx] = NULL; + int fds[2]; popenrw(callProc, fds); + ScopeObject doClose([&] { + close(fds[0]); + close(fds[1]); + }); char buf[BUFSIZ]; while (ssize_t r = read(fds[1], buf, BUFSIZ) != 0) { if (r < 0) { @@ -39,8 +45,6 @@ class ProcessStream : public Stream, IHaveParameters { sink(buf, r); } - close(fds[0]); - close(fds[1]); int status; wait(&status); // ignore any error if the application is still running, @@ -51,7 +55,6 @@ class ProcessStream : public Stream, IHaveParameters { } } protected: - mutable int fds[2]; const Variable path; }; |