I have an executable that I need to run some tests on in C++ – and the testing is going to take place on all of Windows, Linux and Mac OSes.
I was hoping for input on:
- How would I interface with the previously built executable from my code? Is there some kind of command functionality that I can use? Also, since I think the commands change between OSes, I’d need some guidance in figuring out how I could structure for all three OSes.
EDIT – Interface = I need to be able to run the executable with a command line argument from my C++ code.
- The executable when called from the commandline also ouputs some text onto a console – how would I be able to grab that ouput stream (I’d need to record those outputted values as part of my tests).
Feel free to ask me follow up questios.
Cheers!
As I understand, you want to:
Libraries such as QProcess can spawn processes, however, I would recommend doing it by hand for both Windows and MacOS/Linux as using QProcess for this case is probably overkill.
For MacOS/Linux, here’s what I would do:
pipein the parent process. Set the read end of the pipe to a new file descriptor in the parent.fork.execvpin the newly created child process and pass the target executable along with what arguments you want to give it.waitfor the child (optional).