There are plenty of questions on here related to fork() and exec(). I have not found one that really makes the process of using them simple though, and making programmer's lives simple is the goal.
I need a C++, linux-friendly function that does the following:
string RunCommand(string command, string input){}
This function should be able to run a shell command, like grep, and "pipe" the content of input into it and read the ouptut and return it. So if I would do the following at the command line:
ps -elf | grep somequerytext
I would in code do:
string psOutput = RunCommand("ps -elf","");
string grepOutput = RunCommand("grep somequerytext", psOutput);
*edit: The question is what is the best implementation of the RunCommand function.
*edit: popen was considered as a solution for simplicity, but popen restricts you to piping data in or piping data out, but not both.
popenOrsystem.popensounds like exactly what you want.