main
bi_popen
Description
bi_popen
Creates two pipes, forks, and runs the given command. One pipe is connected between the given *in and the standard input stream of the child; the other pipe is connected between the given *out and the standard output stream of the child.
Returns the pid of the child on success, -1 otherwise. On error, errno will be set accordingly.
Table of Contents
Features
Todos
Usage
int main(void)
{
FILE* in = NULL;
FILE* out = NULL;
char* line = NULL;
size_t size = 0;
const int pid = bi_popen("/bin/bash", &in, &out);
if (pid < 0) {
perror("bi_popen");
return 1;
}
fprintf(in, "date\n");
getline(&line, &size, out);
printf("-> %s", line);
// Since in this case we can tell the child to terminate, we'll do so
// and wait for it to terminate before we close down.
fprintf(in, "exit\n");
waitpid(pid, NULL, 0);
fclose(in);
fclose(out);
return 0;
}
Acknowledgments
License
This project is licensed under the MIT License - see the MIT License file for details.
Description
Languages
C
100%