title: Execute command with output redirection using exec command in C
body: <p>I need execute a command which redirects output to /dev/null. How to execute commands like this using exec in C ?</p>
  
  <p>My command is <code>ls logs/ &gt;/dev/null 2&gt;/dev/null</code>. To execute this command, I am first splitting the command with space as delimiter and then executing using exec. When executing <code>&gt;/dev/null 2&gt;dev/null</code> are passed as arguments to the script. How we can avoid this ?</p>
  
  <p>I don't want to use system command to overcome this problem.</p>
  
  <p>CODE :</p>
  
  <pre><code>static int
  command_execute(char* command) {
          char **arguments = g_strsplit(command, " ", 32);
          pid_t child_pid;
  
          if( !arguments ) {
              status = COMMAND_PARSE_ERROR;
              goto EXIT;
          }
  
          if( (child_pid = fork() ) == -1 ) {
              status = CHILD_FORK_ERROR;
              goto EXIT;
          }
  
          if( child_pid == 0 ) {
              execvp(arguments[0], arguments);
          } else {
              waitpid(child_pid, &amp;status, 0);
              if(status) {
                  goto EXIT;
              }
          }
  }
  </code></pre>