-1

I found this and this examples to start a Child process with redirected stdin and stdout, but both of them seem to be really outdated and c-based.(using HANDLE and stuff)

Are there any ways to do that with more c++? (Windows, if possible)

_popen() function is close, but it uses FILE* and only allows stdin OR stdout, not both at the same time.

KBOPYM
  • 33
  • 6
  • 4
    `boost::process`, also I must mention that those examples are up to date and any library implementing process spawning is just a wrapper around C API calls and HANDLEs – user7860670 May 08 '18 at 17:52
  • Possible duplicate of [how to control popen stdin, stdout, stderr redirection?](https://stackoverflow.com/questions/280571/how-to-control-popen-stdin-stdout-stderr-redirection) – Ben May 08 '18 at 21:06

1 Answers1

0

Child processes are not defined in the C or C++ standards.

You need to look outside of that to boost, posix or Windows extensions.

Ben
  • 34,935
  • 6
  • 74
  • 113
  • Not entirely true. `system()` in `stdlib.h` is part of the C and C++ standards. OTOH child I/O redirections are platform-dependent (self-redirection is standard using `freopen()` in `stdio.h`). – Ben Voigt May 08 '18 at 21:29
  • @BenVoigt it's not part of the specification of `system` that it creates a child process - it "invokes the command processor". If I'm reading it right, using `system` is actually UB! It's defined by posix to be equivalent to `fork`/`execl sh -c`, but that's posix not C – Ben May 09 '18 at 09:04