Looking for information on how to get the output from a system command and put them into a variable. I am writing a short program, proof of concept to my self, on connecting to a DB2 data source. I am able to connect to the data source. I could crate a bind file and bind it to the DB but I want to try a different route and grap the out put from a system command to list the tables of the DB and keep them in a variable with out them showing on the screen. Any ideas. here is a snippet of my code to try just that. sloppy I know, just trying to get it going.


void DB2Cmd(void)
{
char tables[50];

strcpy(DB2Command,"db2 list tables");
tables[0] = system(DB2Command);

printf ("Name of tables %s ", tables[0]);

printf("\n\n");
}