diff --git a/doc/concepts.qbk b/doc/concepts.qbk index 06658a45..afc5485b 100644 --- a/doc/concepts.qbk +++ b/doc/concepts.qbk @@ -16,7 +16,7 @@ In that it is different than other facilities (like sockets) and provides anothe Pipes are typically used for interprocess communication. The main reason is, that pipes can be directly assigned to the process stdio, i.e. stderr, stdin and stdout. Additionally, half of the pipe can be inherited to the child process and closed in the father process. This will cause the pipe to be broken when the child process exits. -Though please not, that if the the same thread reads and write to a pipe, it will only talk to itself. +Though please note, that if the the same thread reads and write to a pipe, it will only talk to itself. [section:anonymous Anonymous Pipes] diff --git a/include/boost/process/detail/posix/pipe_out.hpp b/include/boost/process/detail/posix/pipe_out.hpp index 9f7da946..d54cca4e 100644 --- a/include/boost/process/detail/posix/pipe_out.hpp +++ b/include/boost/process/detail/posix/pipe_out.hpp @@ -52,8 +52,10 @@ template void pipe_out<1,-1>::on_exec_setup(Executor &e) const { if (::dup2(sink, STDOUT_FILENO) == -1) - e.set_error(::boost::process::detail::get_last_error(), "dup3() failed"); - ::close(sink); + e.set_error(::boost::process::detail::get_last_error(), "dup2() failed"); + + if (sink != STDOUT_FILENO) + ::close(sink); ::close(source); } @@ -63,7 +65,9 @@ void pipe_out<2,-1>::on_exec_setup(Executor &e) const { if (::dup2(sink, STDERR_FILENO) == -1) e.set_error(::boost::process::detail::get_last_error(), "dup2() failed"); - ::close(sink); + + if (sink != STDOUT_FILENO) + ::close(sink); ::close(source); } @@ -75,8 +79,8 @@ void pipe_out<1,2>::on_exec_setup(Executor &e) const e.set_error(::boost::process::detail::get_last_error(), "dup2() failed"); if (::dup2(sink, STDERR_FILENO) == -1) e.set_error(::boost::process::detail::get_last_error(), "dup2() failed"); - ::close(sink); - ::close(source); + if ((sink != STDOUT_FILENO) && (sink != STDERR_FILENO)) + ::close(sink); } class async_pipe;