0

I want to pipe the stdout of a child process that is created in the main program into a input stream owned by the main process.

I have a java equivalent to what I want to do, but I have no clue how to do this in C++

final Process p = Runtime.getRuntime().exec(/* Some process */);
final InputStream reader = p.getInputStream();
final byte[] buf = new byte[4096];
int offset;

while (p.isAlive()) {
   offset = reader.read(buf);
   if (offset == -1)
      break;
   // Do something with buf here
}
Colby Quinn
  • 148
  • 1
  • 7
  • @JaMiT I want to pipe the stdout of a child process that is created in the main program into a input stream owned by the main process. – Colby Quinn Dec 04 '20 at 21:49
  • 1
    Does this answer your question [Two way parent child communication in windows with c++](https://stackoverflow.com/questions/32501274/two-way-parent-child-communication-in-windows-with-c)? – JaMiT Dec 05 '20 at 00:32

1 Answers1

-1

Please see this article in MSDN:

Creating a Child Process with Redirected Input and Output

Tumbleweed53
  • 1,427
  • 6
  • 10
  • Thanks I was looking into that and found _popen that does exactly what I need, should have updated the thing that I found that. – Colby Quinn Dec 04 '20 at 23:17
  • Please review [answer]. in particular the part under the heading "Provide context for links" that reads *"Always quote the most relevant part of an important link, in case the external resource is unreachable or goes permanently offline."* (While Microsoft is unlikely to go offline in the near future, they have in the past re-arranged their documentation, causing existing links to go dead.) – JaMiT Dec 05 '20 at 00:36