title: read and write with the same process using two different pipes c++
body: <p>I am trying to create a child that calls some program or process. The parent write and read some data from child through a two pipes. My code compiles and runs, but there is no text on input. What am I doing wrong? Am I not closing the pipes correctly, writing the pipes or outputting the data correctly?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;errno.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;  
  #include &lt;unistd.h&gt;
  #include &lt;string.h&gt;  
  
  int main(){
     int pipedes1[2],pipedes2[2];
     char buff[256];
     string text = "Hello";
     pid_t pid;
     pipe(pipedes1);
     pipe(pipedes2);
     pid = fork();
     if(pid &gt; 0){
  
         close(pipedes1[1]);
         close(pipedes2[0]);
  
         dup2(pipedes2[1], STDOUT_FILENO);
         dup2(pipedes1[0], STDIN_FILENO);
  
         execve("/home/pi/Test", NULL, NULL);
  
     } else {
  
         close(pipedes1[1]);
         close(pipedes2[1]);
  
         write(pipedes1[0], text.c_str(), text.length());
         while((len = read(pipedes2[0], buff, 256)) != 0){
              cout &lt;&lt; buff &lt;&lt; endl;
         }
         close(pipedes2[0]);
         close(pipedes1[0]);
     }
     return 0;
  }
  </code></pre>
  
  <p>And there is my "chield" program:</p>
  
  <pre><code>int main(){
      string str;
      cin &gt;&gt; str;
      str = "echo " + str + " &gt;&gt; /home/pi/1";
      cout &lt;&lt; str &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>Output of prog:</p>
  
  <blockquote>
    <p>echo   &lt;&lt; /home/pi/1</p>
  </blockquote>
  
  <p>Im found a problem write() returns -1.
  But i dont know why?</p>