12
Jun
stored in: Linux, Programming Tips and tagged:
Ever wanted to grab the output of a command via C++? In PHP, we are all very familiar with @exec and popen, but what about C++? Try this: string cmd = “/usr/bin/netstat -na”; string OutString; FILE *FileStream; char stdbuffer[1024]; FileStream = popen(cmd.c_str(), “r”); while (fgets(stdbuffer, 1024, FileStream) != NULL) OutString.append(stdbuffer); pclose(FileStream); The first 3 lines [...]