Boost logo

Boost Users :

From: Nicholas Yue (yue.nicholas_at_[hidden])
Date: 2023-02-02 06:23:41


Hi,

  Is it possible to write both the stdout and stderr stream to the same
output file/stream ?

  I am hoping to emulate

```
bp_stdout_stderr_app > output.txt 2>&1
```

  I tried doing something like that but get a runtime error

Run output
```
terminate called after throwing an instance of
'boost::process::process_error'
  what(): dup3() failed: Bad file descriptor
stdout : 000
stdout : 020
stdout : 040
Aborted (core dumped)
```

Source code
```
#include <boost/process.hpp>
#include <iostream>

using namespace boost::process;

int main()
{
    ipstream pipe_stream;
    child c("bp_stdout_stderr_app", std_out > pipe_stream, std_err >
pipe_stream);

    std::string line;

    while (pipe_stream && std::getline(pipe_stream, line) && !line.empty())
        std::cerr << line << std::endl;

    c.wait();
}
```

Cheers

-- 
Nicholas Yue
https://www.linkedin.com/in/nicholasyue/


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net