38 lines
733 B
C
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;
|
|
}
|
|
|