title: Spawning interactive CLI command with Expect exits with 0 early, when run as Symfony Process in Behat context
body: <p>This is quite an advanced question, perhaps knowledge of Symfony and Behat may not be necessary to understand the problem.</p>
  
  <p>So in order to test the input and output of an interactive CLI app <code>bin/albumgrab</code> I've written in PHP using the Symfony Console component, I've set up my Behat feature context to build an <code>expect</code> script, run via <code>exec</code>.</p>
  
  <p>This <code>exec</code> command is run in PHP via Symfony <code>Process</code>.</p>
  
  <pre><code>$expect = &lt;&lt;&lt;BASH
  exec expect -c '
      set timeout 180
      spawn bin/albumgrab
      expect "Please enter the name of the directory"
      send "/tmp/php-london\n"
      expect "Please enter the URL to the first image"
      send "https://www.facebook.com/PeeHPLondon/photos/pb.7119218495.-2207520000.1430669248./10153559172718496/?type=3&amp;src=https%3A%2F%2Ffbcdn-sphotos-g-a.akamaihd.net%2Fhphotos-ak-xfp1%2Fv%2Ft1.0-9%2F10986697_10153559172718496_5727444485530442900_n.jpg%3Foh%3Dc47770f4cd15fecc6888bcd504899087%26oe%3D55DA9CB0%26__gda__%3D1439174101_7c78a93bf247dbad6c56681b6db5309c&amp;size=960%2C959&amp;fbid=10153559172718496\\n"
      interact
  '
  
  BASH;
  
  $process = new Symfony\Component\Process\Process($expect);
  
  $process-&gt;mustRun();
  </code></pre>
  
  <p>However, when it gets past the second input, it seems to exit but successfully.</p>
  
  <p>Calling:</p>
  
  <pre><code>$process-&gt;setTty(true);
  </code></pre>
  
  <p>Makes it run all the way through, but will print straight to stdout and I can no longer capture the output to make an assertion, not even with PHP's output buffering.</p>
  
  <p>I figured PTY would be more suitable anyway:</p>
  
  <pre><code>$process-&gt;setPty(true);
  </code></pre>
  
  <p>As it was the solution to <a href="https://stackoverflow.com/questions/27022516/controlling-an-interactive-process-with-php-using-symfony-process">this StackOverflow question</a>. However, this is not supported everywhere, at least not on Mac OS X. </p>
  
  <p>You can see what I've attempted so far in Github: <a href="https://github.com/adamelso/albumgrab/pull/13/files" rel="nofollow noreferrer">https://github.com/adamelso/albumgrab/pull/13/files</a> and the Travis output for the last attempt <a href="https://travis-ci.org/adamelso/albumgrab/jobs/61137499" rel="nofollow noreferrer">https://travis-ci.org/adamelso/albumgrab/jobs/61137499</a></p>
  
  <p>So my main question is why it keeps exiting with 0 early and how to prevent it?</p>