1234567891011121314151617181920212223242526272829 |
- #include <stdio.h>
- int main(void) {
- FILE *fp;
- int status;
- char path[256];
- fp = popen("ls -1 example_dir", "r");
- if (fp == NULL) {
- perror("popen");
- return -1;
- }
- while (fgets(path, 256, fp) != NULL) {
- printf("%s", path);
- }
- status = pclose(fp);
- if (status == -1) {
- perror("pclose");
- return -1;
- } else {
- printf("status %x\n", status);
- }
- return 0;
- }
|