Thank you guys for answering "capturing commandline output directly in a buffer" .. thanks a lot.. I used popen() to get my results correct.
here i have one more thing may be small one
I need to print something in my window when the script "check.sh" returns nothing, means validation when no output from the script is returned.
check.sh contains nothing in it.. simply a blank sh file returns nothing when executed.I am testing with empty sh file.(I cannot show u the exact script that is why)
what i want to print is some message like "configure some thing" through C when check.sh returns nothing.
I checked buffer line(check in the module below) with "\n","\r","\0",NULL.. I donno what it is taking when the script returns nothing
I ll be calling the module as execute_command("sh check.sh")
Here is my module
char *execute_command(char *command)
{
FILE *fpipe;
char line[1024]="";
//char *line = (char*)malloc(1024*sizeof(char));
int i =0;
if ( !(fpipe = (FILE*)popen(command,"r")) )
{ // If fpipe is NULL
perror("Problems with pipe");
exit(1);
}
while ( fgets( line, sizeof line, fpipe))
{
// printf("%s", line);
}
while(line[i]!='\0')
{
if(line[i]==' ')
{
line[i]=',';
}
i++;
}
pclose(fpipe);
printf("%s",line);//This is where i want to know what the buffer has when the script returns nothing
return(line);
}
May be a simple one.. I got stuck in this.. help me.
Thanks in advance