I am trying to interact with an external program in C using pipe, forkand exec. I want to force an external program to execute unbuffered I / O. Here is the corresponding code snippet from my code:
...
pid = fork();
if (pid == (pid_t) 0)
{
dup2(wpipe[0], STDIN_FILENO);
dup2(rpipe[1], STDOUT_FILENO);
close(wpipe[0]); close(rpipe[0]);
close(wpipe[1]); close(rpipe[1]);
setvbuf(stdin, NULL, _IONBF, BUFSIZ);
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
if (execl("path/to/some_binary", "path/to/some_binary", (char *) NULL) == -1)
{
fprintf(stderr, "exec failed\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
...
This does not work because the threads do not go beyond the calls exec. Thus, using setvbufforced unbuffered I / O does not work because the program image ( some_binary) creates its own streams stdin and stdout and does not use the streams that I called setvbufon.
, some_binary setvbuf . , , exec? , , unix, , cat ls?