title: Why child process returns exit status = 32512 in unix?
body: <p>In my program I'm executing given command and getting result (log, and exit status). Also my program have to support shell specific commands (i.e. commands which contains shell specific characters ~(tild),|(pipe),*). But when I try to run <code>sh -c ls | wc</code> in my home directory via my program it failed and its exit status was 32512, also in stderr stream <code>"sh: ls | wc: command not found"</code> was printed.</p>
  
  <p>But the interesting thing is that the command <code>sh -c ls | wc</code> works correct if I run it in shell. </p>
  
  <p>What is the problem? Or more preferable how can I run shell specific commands via my program (i.ec which command with which parameters should I run)?</p>
  
  <p>The code part bellow is in child part after fork(). It executs the command.</p>
  
  <p><code>tokenized_command</code> is <code>std::vector&lt;std::string&gt;</code> where in my case <code>"sh", "-c", "ls", "|", "wc"</code> are stored, also I have tried to store there <code>"sh", "-c", "\"ls | wc\""</code> but result is same. <code>command</code> is <code>char *</code> where full command line is stored.</p>
  
  <pre><code>        boost::shared_array&lt;const char *&gt; bargv(new const char *[tokenized_command.size() + 1]);
          const char **argv = bargv.get();
          for(int i = 0; i &lt; tokenized_command.size(); ++i)
          {
              argv[i] = tokenized_command[i].c_str();
              printf("argv[%d]: %s\n", i, argv[i]); //trace
          }
          argv[tokenized_command.size()] = NULL;
  
          if(execvp(argv[0], (char * const *)argv) == -1)
          {
              fprintf(stderr, "Failed to execute command %s: %s", command, strerror(errno));
              _exit(EXIT_FAILURE);
          }
  </code></pre>
  
  <p>P.S.</p>
  
  <p>I know that using <code>system(command)</code> instead <code>execvp</code> can solve my problem. But <code>system()</code> waits until command is finished, and this is not good enough for my program. And also I'm sure that in implementation of <code>system()</code> one of exec-family functions is used, so the problem can be solved via <code>exec</code> as well, but I don't know how.</p>