exectd/tests/01_exectd.c
2024-11-15 19:41:47 -06:00

38 lines
733 B
C

#include "../include/exectd.h"
#include <stdlib.h>
#include <sys/wait.h>
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(out, "pwd\n");
getline(&line, &size, in);
printf("-> %s", line);
fprintf(out, "date\n");
getline(&line, &size, in);
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(out, "exit\n");
waitpid(pid, NULL, 0);
fclose(in);
fclose(out);
free(line);
return 0;
}