title: Using execv (C language) to run commands from a linux command prompt
body: <p>The only part I am confused on thus far is how to set up execv with the first parameter as the current working directory. I've tried both "." and "~", neither are executing anything to the screen; same for "/." and "/~". I'm confused on how to have execv run something like this:</p>
  
  <pre><code>$ ./prog ls -t -al
  </code></pre>
  
  <p>And have it execute the commands after the program execution (which are stored into argv) in the current directory, or the same directory as the file is in (which will vary based on who is using it.)</p>
  
  <p>My code:</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  
  void main(int argc, char *argv[])
  {
      int pid;
      int count = 0;
      char *argv2[argc+1];
  
      for(count = 0; count &lt; argc-1; count++){
          argv2[count] = argv[count+1];
          printf("Argv2: %s\n", argv2[count]);  //just double checking
          argv2[argc-1] = NULL;
      }
  
      pid = fork();
      if(pid == 0){
          printf("Child's PID is %d. Parent's PID is %d\n", (int)getpid, (int)getppid());
          execv(".", argv2);       //&lt;---- confused here
      }
      else{
          wait(pid);
          exit(0);
      }
  }
  </code></pre>
  
  <p>Some sample output:</p>
  
  <pre><code>$ ./prog ls -t -al
  Argv2: ls
  Argv2: -t
  Argv2: -al
  Child's PID is 19194. Parent's PID is 19193
  </code></pre>