title: getting shell command from user input and executing C program
body: <p>currently working on program which recieves input command for linux shell and executing them creating child process.</p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;errno.h&gt;
  
  int main(int argc, char * argv[])
  { 
    int pid, status;
    if (argc &lt; 2) {
      printf("Usage: %s command, [arg1 [arg2]...]\n", argv[0]);
      return EXIT_FAILURE;
    }
    printf("Starting %s...\n", argv[1]);
    pid = fork();
    if (pid == 0) {
      execvp(argv[1], &amp;argv[1]);
      perror("execvp");
      return EXIT_FAILURE; // Never get there normally
    } else {
      if (wait(&amp;status) == -1) {
        perror("wait");
        return EXIT_FAILURE;
      }
    }
    return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>Works with input like <code>./program command arg</code> but needed to receive various commands with args for example : <code>./program command arg command arg .....</code> </p>
  
  <p>Any suggestions?</p>