+ _pipe_fd[READ]= -1;
+ _pipe_fd[WRITE]= -1;
+ _open[READ]= false;
+ _open[WRITE]= false;
+}
+
+int Application::Pipe::Pipe::fd()
+{
+ if (_std_fd == STDOUT_FILENO)
+ {
+ return _pipe_fd[READ];
+ }
+ else if (_std_fd == STDERR_FILENO)
+ {
+ return _pipe_fd[READ];
+ }
+
+ return _pipe_fd[WRITE]; // STDIN_FILENO
+}
+
+
+bool Application::Pipe::read(libtest::vchar_t& arg)
+{
+ fatal_assert(_std_fd == STDOUT_FILENO or _std_fd == STDERR_FILENO);
+
+ bool data_was_read= false;
+
+ ssize_t read_length;
+ char buffer[1024]= { 0 };
+ while ((read_length= ::read(_pipe_fd[READ], buffer, sizeof(buffer))))
+ {
+ if (read_length == -1)
+ {
+ switch(errno)
+ {
+ case EAGAIN:
+ break;
+
+ default:
+ Error << strerror(errno);
+ break;
+ }
+
+ break;
+ }
+
+ data_was_read= true;
+ arg.reserve(read_length +1);
+ for (size_t x= 0; x < read_length; x++)
+ {
+ arg.push_back(buffer[x]);
+ }
+ // @todo Suck up all errput code here
+ }
+
+ return data_was_read;
+}
+
+void Application::Pipe::nonblock()
+{
+ int ret;
+ if ((ret= fcntl(_pipe_fd[READ], F_GETFL, 0)) == -1)
+ {
+ Error << "fcntl(F_GETFL) " << strerror(errno);
+ throw strerror(errno);
+ }
+
+ if ((ret= fcntl(_pipe_fd[READ], F_SETFL, ret | O_NONBLOCK)) == -1)
+ {
+ Error << "fcntl(F_SETFL) " << strerror(errno);
+ throw strerror(errno);
+ }