#include #include #include #include #define TRUE 1 #define FALSE 0 int main (int argc, char *argv[]) { char line[2000], master_buffer[10000], input_video_filename[1280]; int i, fd[2], n, process_status, child_pid, bytes_read, total_bytes_read; pid_t wpid; total_bytes_read = 0; memset (&master_buffer[0], 0, sizeof(master_buffer)); strcpy (&input_video_filename[0], "video.avi"); if (pipe(fd) < 0) { printf ("pipe() failed.\n"); exit (EXIT_FAILURE); } switch (child_pid = fork()) { case -1: printf ("fork() error\n"); exit (EXIT_FAILURE); case 0: // child dup2 (fd[1], 1); // 0 is STDIN (read), 1 is STDOUT (write)! dup2 (STDOUT_FILENO, STDERR_FILENO); // redirect standard error to standard out. close (fd[0]); // the child does not need this end of the pipe execl ("/usr/local/bin/ffprobe", "/usr/local/bin/ffprobe", "-i", &input_video_filename[0], (char *) NULL); exit (EXIT_FAILURE); // should not make it here! default: // parent close (fd[1]); // the parent does not need this end of the pipe memset (&line[0], 0, sizeof(line)); bytes_read = read(fd[0], &line[0], sizeof(line) - 1); while (bytes_read > 0) { line[bytes_read] = '\0'; total_bytes_read = total_bytes_read + bytes_read; if (total_bytes_read < (sizeof(master_buffer) - 1)) { strcat (master_buffer, line); } else { printf ("Exceeded master buffer size\n"); } bytes_read = read(fd[0], line, sizeof(line) - 1); } wpid = waitpid (child_pid, &process_status, 0); if (wpid < 0) { printf ("waitpid error\n"); exit (EXIT_FAILURE); } break; } for (i = 0; i < total_bytes_read; i++) { putchar (master_buffer[i]); } }