B
barncat
hi
I am reading data from a popen call (server) and sending the data to a
client. It works fine except funny chars are prepended to the string
sent and displayed at the client. here is the relevant code:
--
FILE *FP;
char string[32];
char buf[128];
FP = popen("lparstat -i | head -5 | tail -2","r");
while(fgets(buf,128,FP) != NULL) {
strcat(string,buf);
squeeze(string); //function to remove spaces
}
pclose(FP);
if (send(socket, string, strlen(string), 0) == -1)
perror("Writing String to client");
--
/* function to remove spaces */
int squeeze(char *s) {
char *t = s;
for(;*s;(*s != ' ') ? *t++ = *s++ : *s++)
continue;
*t = '\0';
}
--
Output from client:
-bash-2.05b$ ./program
received answer to query from server:
/ò,¸/ò,ÀTypeedicated
Mode:Capped
I am reading data from a popen call (server) and sending the data to a
client. It works fine except funny chars are prepended to the string
sent and displayed at the client. here is the relevant code:
--
FILE *FP;
char string[32];
char buf[128];
FP = popen("lparstat -i | head -5 | tail -2","r");
while(fgets(buf,128,FP) != NULL) {
strcat(string,buf);
squeeze(string); //function to remove spaces
}
pclose(FP);
if (send(socket, string, strlen(string), 0) == -1)
perror("Writing String to client");
--
/* function to remove spaces */
int squeeze(char *s) {
char *t = s;
for(;*s;(*s != ' ') ? *t++ = *s++ : *s++)
continue;
*t = '\0';
}
--
Output from client:
-bash-2.05b$ ./program
received answer to query from server:
/ò,¸/ò,ÀTypeedicated
Mode:Capped