Process.exec() ne se termine pas, impossible de lire le InputStream (windows)
Bonjour à tous,
J'ai besoin d'executer un script php depuis du java. J'ai donc utilisé la classe Process de java comme ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| String[] cmd = new String[3];
cmd[0] = "cmd.exe";
cmd[1] = "/C";
cmd[2] = cheminPhp + " -q " + cheminFichierPhp + " -file " + cheminFichierEntree + " -logtype stderr";
//ou solution 2
String cmd = cheminPhp + " -q " + cheminFichierPhp + " -file " + cheminFichierEntree + " -logtype stderr";
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(cmd);
InputStream in = p.getInputStream();
int val = in.read();//skip \n
System.out.println("première lecture ok");
while(val!=-1){
out.write(val);
val = in.read();
}
System.out.println("lecture terminée"); |
Sous windows, le premier read() reste bloquant, peut importe cmd... Le processus PHP.exe est bien créé, mais ne se termine pas.
Sous linux, la solution 2 fonctionne (normal que la solution 1 ne fonctionne pas).
Une solution ?