title: Passing program one output as input for program two
body: <p>I am looking to find a way to pass the output of program one to the input of program two. I have created two very simple programs to try and understand how to do this but I am having problems.</p>
  
  <p>ProgramOne:</p>
  
  <pre><code>#include &lt;iostream&gt;
  int main()
  {
      using namespace std;
      std::cout &lt;&lt; "Hello World!";
      return 0;
  }
  </code></pre>
  
  <p>ProgramTwo (prints all arguments):</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main(int argc, char *argv[])
  {
      using namespace std;
  
      cout &lt;&lt; "There are " &lt;&lt; argc &lt;&lt; " arguments:" &lt;&lt; endl;
  
      // Loop through each argument and print its number and value
      for (int nArg=0; nArg &lt; argc; nArg++)
          cout &lt;&lt; nArg &lt;&lt; " " &lt;&lt; argv[nArg] &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>I have tried using the pipe command to pass the output:</p>
  
  <pre><code>./one | ./two
  </code></pre>
  
  <p>but my second program is only printing a single argument:</p>
  
  <pre><code>There are 1 arguments:
  0 ./two
  </code></pre>
  
  <p>I have also tried the following command:</p>
  
  <pre><code>/one &gt; ./two
  </code></pre>
  
  <p>But this results in no output from either program.</p>
  
  <p>Where am I going wrong?</p>