#include #include #include #include #include using namespace std; string getoutput(const char* cmd){ FILE *pipe = popen(cmd, "r"); string return_string; char buffer[1024]; buffer[1023] = 0; size_t readlen; while((readlen = fread(buffer, 1, 1023, pipe)) == 1023){ return_string += buffer; } buffer[readlen] = 0; return_string += buffer; pclose(pipe); return return_string; } int main(int argc, char ** argv){ string output = getoutput(argv[1]); cout << output << endl; printf("Length was %lu bytes\n", output.length()); return 0; }