In C++, I need to start a secondary program from a primary program, sending the second some arguments. I need to return the data produced by the secondary program to the primary program. In this case, the data happens to be a two-dimensional std::string array; we’ll call it stringArray. This is easy enough to do:
// snippet from Primary
std::string executionString ("./secondaryProgram arg1 arg2 arg3");
system(executionString);
What I don’t know how to do is get the data that Secondary Program produces back to the Primary program (short of writing to a temporary file from Secondary and then reading the file from Primary).
In other words, it would be great if I could do something like:
// snippet from Primary
std::string stringArray[2][3];
stringArray = system(executionString);
I’m not hoping for a solution as simple as this or working code from anyone, any nudge in the right direction is appreciated.
I cannot use sockets for this purpose. I have not been able to figure out how to build a pipe between std::cout and std::cin that works for this case. My only real constraint is that my solution involve system() somehow.
Alright here’s what I ended up doing.
“translate”
“dictionary”
“dictionary.txt”
meant to be run like
$ ./dictionary Apple Orange Strawberryproduces “translated.txt”
I’ve still got a bit of polishing to do before I turn it in, but that’s the gist of it. Thanks guys!