c++ - Reading from pipe into buffer character by character/find the size of data in pipe -


i'm working pipes using "unistd.h" , "sys/wait.h" os homework. i'm trying implement graph pipe.

since in graph pipe there possibility output of process can sent more 1 process input, need store in buffer , send in loop.

to read output process, use read() function. problem since number of characters in output variable, either need read 1 character 1 or somehow find size of output.

i'm trying first option. here code

string buffer; char temp[1]; while (/*condition*/) {     read (pipe[0], temp, 1);     buffer.push_back (temp[0]); } 

my question condition must inside of loop?

p.s. if second option easier how can check size of output of process in pipe?

the condition return of read call:

while (read(...) == 1) { ... } 

also don't forget address-of operator, can use instead of declaring temp array:

char temp; while (read(pipe[0], &temp, sizeof(temp)) == sizeof(temp)) { ... } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -