title: putting output of execvp into string
body: <p>I have a shell that has a function which eventually calls execvp(...) which gives an output. For example "echo hello" gives an output of "hello". Everything works, don't worry. I have tested it very much, I just didn't put the full code here because it is 1000 lines of code.</p>
  
  <p>How can i take that output from execvp, dup2 it, and put it into a string?</p>
  
  <p>I know I use dup2, but I'm not sure how.</p>
  
  <p>I have these throughout my code:</p>
  
  <pre><code>char* globalString;   //a global string I want to put the output into
  char* myString = "one two three ";
  char* append = "echo four";
  int myPipe[2];  //my pipe  
  pipe(myPipe);
  </code></pre>
  
  <p>then I call my function and I want to pass the write end of pipe into it.</p>
  
  <pre><code> myfunction( ... , [pointer to write end of pipe]); //i don't know how    
  
    //ignoring previous code
  
  
    cpid = fork();
    if(cpid &lt; 0){
       //Fork wasn't successful 
       perror("fork");
       return -1;
    }
  
    //in the child
    if(cpid == 0){
  
       execvp(...);  // in this example, this prints "four" to stdout        
  
       //execvp returned, wasn't successful
       perror("exec");
  
       fclose(stdin);  
  
       exit(127);
    }
  
  //then more code happens
  }
  </code></pre>
  
  <p>at the end, I want the output from exec to be put into globalString. Then I put globalString into myString, so that myString is "one two three four"</p>
  
  <p>thank you.</p>