2
0

popen.c 341 B

1234567891011121314151617
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "test_helpers.h"
  4. int main(void) {
  5. FILE *fp = popen("ls -1 example_dir", "r");
  6. ERROR_IF(popen, fp, == NULL);
  7. char path[256] = { 0 };
  8. while (fgets(path, 256, fp) != NULL) {
  9. printf("%s", path);
  10. }
  11. int status = pclose(fp);
  12. ERROR_IF(pclose, status, == -1);
  13. }