I'm writing a program that needs to call a shell command during runtime. The output of said command needs to come back into the program as a c++ string.
At first I just used
However, this is horrendously slow and isn't practical. I want to redirect the output from shell directly into my program. I attempted
system("echo Hello World > temp");
string hello = getFile("temp");//where getFile simply returns the contents of temp as a string.
but this failed also.
system("echo Hello World 1>&0");
hello += c;
If anyone can help, it would be greatly appreciated. I have a basic knowledge of C++ but only a rough understanding of bash shells, and so may be missing something obvious.