Hi All
I'm triing to catch the output from a g++ command
from my ui. I'm using popen to get a file pointer
from which I read output. The catch is that this
works fine with regular shell commands like
"ps -ax\n" but with g++ the output goes to stderr.
As near as I can tell there is no way to read this
with popen. Yes I can pipe all the output to a file
and then read that but it's a kludge and I think
there must be a better way.
code
(This is c code really that lives in a c++ app.)
void execCompile(char* command,Fl_Browser* b)
{
FILE* read_fp;
char* buffer[BUFSIZ+1];
char* back_wash=(char*)malloc(20000); //big ass bunch of errors.
memset(buffer,'\0',sizeof(buffer));
memset(back_wash,'\0',20000);
int chars_read;
read_fp=popen(command,"r"
;
if(read_fp!=NULL)
{
char* place=back_wash;
chars_read=fread(buffer,sizeof(char),BUFSIZ,read_fp);
memcpy((void*)place,buffer,chars_read);
place+=chars_read;
while(chars_read>0)
{
buffer[chars_read-1]='\0';
printf("READING %d: %s",chars_read,buffer);
memcpy((void*)place,buffer,chars_read);
chars_read=fread(buffer,sizeof(char),BUFSIZ,read_fp);
}
if(pclose(read_fp)==-1)
printf("pclose failed\n"
;
printf("**********************************************************\n"
;
printf("%s",back_wash);
free(back_wash);
return;
}
printf("ERROR opening pipe\n"
;
return;
}
I'm triing to catch the output from a g++ command
from my ui. I'm using popen to get a file pointer
from which I read output. The catch is that this
works fine with regular shell commands like
"ps -ax\n" but with g++ the output goes to stderr.
As near as I can tell there is no way to read this
with popen. Yes I can pipe all the output to a file
and then read that but it's a kludge and I think
there must be a better way.
code
(This is c code really that lives in a c++ app.)
void execCompile(char* command,Fl_Browser* b)
{
FILE* read_fp;
char* buffer[BUFSIZ+1];
char* back_wash=(char*)malloc(20000); //big ass bunch of errors.
memset(buffer,'\0',sizeof(buffer));
memset(back_wash,'\0',20000);
int chars_read;
read_fp=popen(command,"r"
if(read_fp!=NULL)
{
char* place=back_wash;
chars_read=fread(buffer,sizeof(char),BUFSIZ,read_fp);
memcpy((void*)place,buffer,chars_read);
place+=chars_read;
while(chars_read>0)
{
buffer[chars_read-1]='\0';
printf("READING %d: %s",chars_read,buffer);
memcpy((void*)place,buffer,chars_read);
chars_read=fread(buffer,sizeof(char),BUFSIZ,read_fp);
}
if(pclose(read_fp)==-1)
printf("pclose failed\n"
printf("**********************************************************\n"
printf("%s",back_wash);
free(back_wash);
return;
}
printf("ERROR opening pipe\n"
return;
}