arun11299 / cpp-subprocess

Subprocessing with modern C++
Other
458 stars 91 forks source link

Simple stderr example #15

Closed fxfactorial closed 4 years ago

fxfactorial commented 6 years ago

Hi,

I'm looking for a way to collect only stderr from a subprocess, can you provide such an example please?

arun11299 commented 6 years ago

Hello @fxfactorial From the current example:

auto p = Popen({"grep", "f"}, output{PIPE}, input{PIPE});
  const char* msg = "one\ntwo\nthree\nfour\nfive\n";
  p.send(msg, strlen(msg));
  auto res = p.communicate(nullptr, 0);
  std::cout << res.first.buf.data() << std::endl;

res.second.buf is basically the error data. Does this information help you with your case ?