#include <stdio.h>
#include <unistd.h>     /* for execvp */
#include <stdlib.h>	/* for malloc */

/* Another exec example code - this uses argv
   (from the command line). We must build a new
   array of arguments (otherwise we would tell
   exec to exec this program (recursivly and
   infinitely...) */

int main(int argc, char **argv) {
  char **newargs;
  int i;

  /* allocate enough memory for new array of pointers */
  newargs = malloc(sizeof(char *) * argc);

  /* copy all but the first pointer */
  for (i=1;i<argc;i++) {
	newargs[i-1]=argv[i];
  }
  /* execv expects a null terminated list of pointers ! */
  newargs[argc]=NULL;

  /* execute the command build from our command line args */
  if (execvp(newargs[0],newargs)) {
	perror("Huh?");
  }
  return(0);  /* only gets here is execvp failed! */
}


