Files

65 lines
1.4 KiB
Markdown
Raw Permalink Normal View History

2026-07-01 20:26:10 -05:00
# 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](#features)
* [Todos](#todos)
* [Usage](#usage)
* [Acknowledgments](#acknowledgments)
* [License](#license)
## Features
## Todos
## Usage
```c
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
[Unix Stack Exchange](https://unix.stackexchange.com/questions/606861/programming-communicating-with-chess-engine-stockfish-fifos-bash-redirecti)<br>
## License
This project is licensed under the MIT License - see the [MIT License](LICENSE.md) file for details.