Okay, so basically I'm trying to write a program that I can use to convert video files and transfer them to my mp3 player.

The basic part worked fine initially, using system(), I would call ffmpeg, have it convert the file, then use system again to call mtp-sendtr. The problem is, I need to specify the length of the video in seconds to mtp-sendtr. I can check the length myself and input it manually, and that works, but since ffmpeg displays the length as it converts, it seems I could use this data somehow.

First, I tried simply piping the output from ffmpeg to a text file like "ffmpeg blah blah blah > output.txt" but that doesn't work, the file ends up being blank.

So I did this (I've replaced ffmpeg with ls just to simplify things):

Code:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>


int main(int argc, char *argv)
{
int fd; /*file descriptor to the file we will redirect ls's output*/

if((fd = open("dirlist.txt", O_RDWR | O_CREAT))==-1){ /*open the file */
  perror("open");
  return 1;
}


dup2(fd,STDOUT_FILENO); /*copy the file descriptor fd into standard output*/

dup2(fd,STDERR_FILENO); /* same, for the standard error */


close(fd); /* close the file descriptor as we don't need it more  */

/*execl ls */
 execl("/bin/ls", "ls", (char *) 0);

printf("All done.\n");

return 0;
}
That works, of course, but then the program just ends. I don't know much about forks and dup2 and all that, and I'm trying to learn, but I can't find anything that seems to answer my questions.

I have a feeling I'm going about this in a convoluted way, and I'd LOVE to have someone explain to me what I need to do to make this work.