get popen output

Hi, im trying to get popen() output this way:
1
2
3
4
char output[100];
FILE *p = popen("g++ main.cpp -o main", "r");
if(p != NULL) {
	while(fgets(output, sizeof(output), p) != NULL) {

the problem is that it gets the output in console not in the string, what should i do?
Im not sure I get what your problem is, it seems to work fine for me. However, you should be aware that the output from g++ is most likely going to go to SDTERR and not STDOUT. You can capture that too using this:
 
FILE *p = popen("g++ main.cpp -o main 2>&1", "r");

thanks it works!
Topic archived. No new replies allowed.