title: Executing a command with execvpe in C
body: <p>For a project, I'm supposed to pipe the output of a command to my C program (called execute), which will then execute that command.</p>
  
  <p>For example, running this:
  <code>echo ls -lR /usr | ./execute</code>, will take the output (<code>ls -lR /usr</code>) and pass it into my C program which will then execute <code>ls -lR /usr</code>.</p>
  
  <p>According to the directions, I'm supposed to use <code>execvpe()</code> to do the actual execution of the program, however I can't find any documentation that makes sense, nor can I get it to work without getting these errors:</p>
  
  <pre><code>execute.c: In function ‘main’:
  execute.c:98: warning: implicit declaration of function ‘getenv’
  execute.c:98: warning: assignment makes pointer from integer without a cast
  execute.c:106: warning: implicit declaration of function ‘execvpe’
  </code></pre>
  
  <p>My professor said that I have to <code>#include &lt;unistd.h&gt;</code>, and <code>&lt;stdio.h&gt;</code> which I did, parse the input to my program (which I did), and then do this:</p>
  
  <pre><code>int main(void) {
      char *path;
      path = getenv("PATH");
      char *envp[] = {path, NULL};
      // the initialized array below could change normally.
      // below is just an example
      char *tests = {"ls", "-lR", NULL};
      int ret = execvpe("ls", tests, envp);
      if(ret == -1) { printf("error\n"); }
      return 0;
  }
  </code></pre>
  
  <p>He then stated that execvpe should find the path correctly and execute everything. But no matter what I keep getting these warnings. Running the program and ignoring the warnings immediately seg faults. Does anyone know how <code>execvpe</code> works or how I can fix this?</p>