c - Test for standard streams piping failed -


after creating function grab stdin, stdout & stderr, wanted test ..

here test code:

int fd[3]; char *buf = calloc(200, sizeof(char)); file *stream; pid_t pid;  pid = opencmd(fd, "/bin/echo", (char *[]){"/bin/echo", "hello!"});  stream = fdopen(fd[2], "r"); while (fgets(buf, 200, stream) != null)     printf("stderr: %s\n", buf); fclose(stream);  stream = fdopen(fd[1], "r"); while (fgets(buf, 200, stream) != null)     printf("stdout: %s\n", buf); fclose(stream);  free(buf); closecmd(pid, fd); 

this not manage work intended. spent hour debugging , not manage trace problem, far managed go, realized using fdopen start using descriptors' streams not work (for reason), using functions work directly file descriptors (such write(2) & read(2)) works fine.

what might possible reason ?

this excerpt: (char *[]){"/bin/echo", "hello!"}); missing final null parameter – user3629249


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -