title: Force input through STDIN/STDOUT using php
body: <p>I wrote a small application in Java and a script in php. I'm basically try to auto fill in a prompt using php while running the proc_open() function. </p>
  
  <p>Here is my Java:</p>
  
  <pre><code>public class InputTester {
      public static void main(String[] args){
          System.out.println("Output line");
          String said = System.console().readLine("Say Something:");
          System.out.println("You said: " + said);
      }
  }
  </code></pre>
  
  <p>And here is the PHP I'm trying to use to run it:</p>
  
  <pre><code>&lt;?php
      $error_output_file = "/tmp/error-output.txt";
  
      $command = "java -jar InputTester.jar";
      $descriptorspec = array(
          0 =&gt; array("pipe", "r"), //stdin
          1 =&gt; array("pipe", "w"), //stdout
          2 =&gt; array("file", $error_output_file, "a") //stderr
      );
      $proc = proc_open($command, $descriptorspec, $pipes);
      if (is_resource($proc)) while ($s = fgets($pipes[1])) {
              echo $s;
              if(strpos($s, "Something:")) fwrite($pipes[0], 'the thing');
      }
  ?&gt;
  </code></pre>
  
  <p>But, when I run 
      php input_tester.php</p>
  
  <p>All I get is:
      Output line</p>
  
  <p>and then it closes. Does anyone know why?..</p>