It's weekend and I am beginning a new Project To make the core part of the Project I need a performance oriented execution of Java with System.in (or other, if other, better options are available) with php
I have connected my php with exec and popen with my java class, but after one execution it starts another java.class doing exactly the same as the one before instead of giving it again to the with System.in waiting java
My php file
var_dump(exec('"C:\Program Files\Java\jdk-12.0.1\bin\java.exe" -Dfile.encoding=UTF-8 -classpath C:\xampp\htdocs\programmierzeugs\phpCallsJava\bin\production\java test');
var_dump(exec('"C:\Program Files\Java\jdk-12.0.1\bin\java.exe" -Dfile.encoding=UTF-8 -classpath C:\xampp\htdocs\programmierzeugs\phpCallsJava\bin\production\java test hi');
and my Java class
public static void main(String[] args){
System.out.println("test123");
Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine();
System.out.println(line);
output is :
string(7) "test123"
string(7) "test123"
through suggestions of @MDuh I changed the program to:
$handle = proc_open('"C:\Program Files\Java\jdk-12.0.1\bin\java.exe" -Dfile.encoding=UTF-8 -classpath C:\xampp\htdocs\programmierzeugs\phpCallsJava\bin\production\java test',
[0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'r']], $pipes);
if ($err = stream_get_contents($pipes[2]))
{
echo $err;
} else {
var_dump(fread($pipes[0], 6));
echo (string) fwrite($pipes[1], 'hi');
var_dump(fread($pipes[1], 3));
}
following problem:
after I read more than 7 chars in (the test string is 'test123'), fread()
randomly deadlocks me (and sometimes does it not) and stream_get_cotents()
does it instantly. Fwrite gives me back a false and I'd guess that's why I don't have anything to read in