1

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.

Here is my Java:

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);
    }
}

And here is the PHP I'm trying to use to run it:

<?php
    $error_output_file = "/tmp/error-output.txt";

    $command = "java -jar InputTester.jar";
    $descriptorspec = array(
        0 => array("pipe", "r"), //stdin
        1 => array("pipe", "w"), //stdout
        2 => 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');
    }
?>

But, when I run php input_tester.php

All I get is: Output line

and then it closes. Does anyone know why?..

Nathan F.
  • 3,250
  • 3
  • 35
  • 69
  • 1
    Have you checked out the answer in http://stackoverflow.com/questions/17468367/interactive-control-of-a-program-using-php - it's very similar – Andy Hoffner Mar 23 '16 at 21:54
  • @ahoffner That question was somewhat helpful, but my real issue is that fgets() requires an EOL and my application requests the input on the same line, so there isn't an EOL yet. I need to know a way around this – Nathan F. Mar 24 '16 at 04:47

0 Answers0