title: system() call or exec() functions not working when i send command with char array in c language
body: <p>I am trying to make video looper in linux. For that i am using mplayer for videos. My program gets list of videos and images from directory and plays them. My problem is when i call mplayer or image viewer from c with char array parameters it is not working. 
  For example,</p>
  
  <pre><code>system("eog -f /home/user/Desktop/Video/screenshot_0000.png");
  </code></pre>
  
  <p>or</p>
  
  <pre><code>system("mplayer -fs /home/user/Desktop/Video/video1.mov");
  </code></pre>
  
  <p>if i call this way it works. But when i get video list from directy and send them with char array it is not working. When i tried system() call it gives 'sh: 1: video1.mov not found' error and when i use exec() fuctions nothing happens. </p>
  
  <p>Here is my code;</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;sys/types.h&gt;
      #include &lt;unistd.h&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;sys/wait.h&gt;
      #include &lt;dirent.h&gt;
      #include &lt;string.h&gt;
  
      #define FILE_PATH "/home/user/Desktop/Video/"
  
      char *getExt (const char *fspec) {
          char *e = strrchr (fspec, '.');
          if (e == NULL)
              e = ""; // fast method, could also use &amp;(fspec[strlen(fspec)]).
          return e;
      }
  
      void get_list(char liste[][150])
      {
          DIR *d;
          struct dirent *dir;
          char *path = ("%s.",FILE_PATH);
          d = opendir(path);
          int counter=0;
          /*if(d != NULL)
          {
              while((dir=readdir(d))!= NULL)
              {
      //          printf("%s\n", dir-&gt;d_name);
                  if(dir-&gt;d_type==DT_REG)
                      file_numbers++;
              }
              closedir(d);
  
          }
          char liste[file_numbers][150];*/
          d = opendir(path);
          if(d != NULL)
          {
              while((dir=readdir(d))!= NULL)
              {
      //          printf("%s\n", dir-&gt;d_name);
                  if(dir-&gt;d_type==DT_REG)
                  {   
                      strncpy(liste[counter],dir-&gt;d_name,150);
      //              printf("%s\n", liste[counter]);
                      counter++;
                  }
              }
              closedir(d);
  
          }
  
      }
  
      int main ()
      {
          int status;
          pid_t child_pid, pid_w;
          DIR *d;
          struct dirent *dir;
          char *path = ("%s.",FILE_PATH);
          d = opendir(path);
          int file_numbers=0;
          int counter = 0;
          if(d != NULL)
          {
              while((dir=readdir(d))!= NULL)
              {
      //          printf("%s\n", dir-&gt;d_name);
                  if(dir-&gt;d_type==DT_REG)
                      file_numbers++;
              }
              closedir(d);
  
          }
          char liste[file_numbers][150];
          get_list(liste);
          /*for(int i = 0; i&lt; file_numbers;i++)
              printf("%s\n", liste[i]);*/
  
          while(1)
          {
              char *ext = getExt(liste[counter]); 
              //printf("eog -f %s/%s\n",PATH,liste[counter]);
              child_pid = fork();
              if(child_pid==0)
              {
                  //printf("-eog -f %s/%s\n",PATH,liste[counter]);
                  if(!strcmp(ext,".JPG") || !strcmp(ext,".jpg") || !strcmp(ext, ".gif") || !strcmp(ext,".png") || !strcmp(ext, ".PNG") || !strcmp(ext, ".GIF"))
                  {   
                      //printf("eog -f %s%s\n",FILE_PATH,liste[counter]);
                      char command[1000];
                      strcpy(command,("eog -f %s%s",FILE_PATH,liste[counter]));
                      //printf("%s", command);
                      execl(command,command,NULL,NULL);
                      sleep(5);
                  }           
                  else if (!strcmp(ext,".mov") || !strcmp(ext, ".mp4") || !strcmp(ext, ".avi") || !strcmp(ext,".wmv"))
                  {
                      //printf("mplayer -fs %s%s\n",FILE_PATH,liste[counter]);
                      char command[1000];
                      strcpy(command,("mplayer -fs %s%s",FILE_PATH,liste[counter]));
                      //printf("%s",command);
                      execl(command,command,NULL,NULL);
  //                  system(command);
  
                  }
                  else 
                      printf("--%s%s",FILE_PATH,liste[counter]);      
              }
              else
              {
                  pid_w = waitpid(child_pid,&amp;status,0);
      //          system("eog -f /home/user/Desktop/Video/screenshot_0000.png");
      //                  sleep(5);
      //                  exit(EXIT_SUCCESS);
              }
              counter++;
              if(counter &gt;=file_numbers)
                  counter =0;
  
          }
      }
  </code></pre>