posix: Using bp::std_out in conjunction with bp::limit_handles
- Dominant language
- C++
- Stars
- 145
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
Boost version: 1.72.0
Platform: Linux
I use `bp::limit_handles` in order to avoid leaking file descriptors to child processes. This works fine, but I was unsuccessful combining this with redirection of `std_out` to a `string` `future`.
```
/* works fine */
std::vector stdOut(4096);
auto child = bp::system("/bin/echo", "1",
bp::std_out > boost::asio::buffer(stdOut),
bp::limit_handles);
/* string is empty */
std::future stdOut;
auto child = bp::system("/bin/echo", "1",
bp::std_out >stdOut,
bp::limit_handles);
```
In the second example, the `future` is valid, but the `string` is empty. When I remove `bp::limit_handles`, `stdOut` contains `"1\n"`.
I recognized that there is a slight difference between `async_out_buffer` ...
```
template
struct async_out_buffer : ::boost::process::detail::posix::handler_base_ext,
::boost::process::detail::posix::require_io_context,
::boost::process::detail::uses_handles
{
...
```
... and `async_out_future`:
```
template
struct async_out_future : ::boost::process::detail::posix::handler_base_ext,
::boost::process::detail::posix::require_io_context
{
...
```
While the former derives from `bp::detail::use_handles` (which seems to avoid closing this file descriptor), the latter doesn't do this.
Is this a by intention or a bug? Is there a way redirecting `std_out` to a `string` together with closing all other file handles?
**Side question:** How can I determine the number of output bytes for the first example (with the vector)?
regards
Christian
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.