Send input to another .exe

Hello there! I hope you are having good day/night! :D.

TL;DR : How to send input into another .exe?

My goal is to create a simple Machine Learning algorithm, such as I've developed a really simple C++ program which sends the questions, example below... (shortened version)

1
2
  std::cout << "Hello, my question is what's 5 + 12" << std::endl;
  int answer = 0; std::cin >> answer;


and now I want to develop another "simple" algorithm which will basically act as me and send input to it(of course, input would be randomised so program will actually learn the answers). I would be glad if someone could tell me how to write such code or where to obtain much more information about this subject(perhaps written or youtube tutorial).
Thank you so much for reading this :P Thank you even much more for answering this!


Last edited on
you can write to a file and read it in the other process, if you want to keep it simple.
you can also use console commands and text files to feed programs; it acts as if the text file were typed into the program at the cin statements. if the second program is fired up multiple times on demand, you can use command line args.

You can talk to yourself over ethernet even if on the same machine, some some effort, and can also talk to yourself over a null modem cable (a special usb cable, these days).

past those simple tricks, you get into interprocess communications which becomes OS specific but not terribly difficult.

how would that look in code? Do you mind throwing an simple example which would specify or show how the following code would look. Such as simple code A which asks for user input and then code 2 which types the answer by itself. That would be great.
which method? I gave like 6 ways...

tcp for example, pseudo code (you can get all the setup stuff online, its involved)

.. setup for localhost
cin >> blah;
sendto(localhost_socket_var, blah, blah.length())

other program
setup for localhost //set up socket to wait until it gets data
receivefrom(localhost_variable, buffer, max)
cout << buffer;


Last edited on
Topic archived. No new replies allowed.