1

I have 2 different executables which use traditional cin/cout to interact with the user.

Lets imagine it is a program that inputs some numbers and outputs the result.

Now I want to write a driving program in C++ that calls these executables and provides inputs to them ("cin>>"'s a value) and also gets the result of their cout.

I tried using system() that makes a command line call that starts the executable. But I am not able to provide a further input(in some cases inputs) to that. Any idea how to do that?

Unfortunately I can't switch the program to take command line arguments.

tadman
  • 208,517
  • 23
  • 234
  • 262
mbaros
  • 825
  • 8
  • 31
  • 3
    Not sure what is your problem, but looks like you need jus redirect stdout and stdin and you done. You do not need write any program. Just do: `yourProgram.exe output.txt` or `yourProgram1.exe output.txt`. – Marek R Apr 14 '20 at 17:46
  • 2
    Use fork, exec and pipes to connect the two programs. See https://stackoverflow.com/q/42311299/1216776 – stark Apr 14 '20 at 17:53
  • 1
    @stark it is windows, based on `winapi` tag. – Marek R Apr 14 '20 at 17:56
  • 4
    Does [this](https://learn.microsoft.com/en-us/windows/win32/procthread/creating-a-child-process-with-redirected-input-and-output?redirectedfrom=MSDN) answer your question? – David Schwartz Apr 14 '20 at 17:58

0 Answers0