est ce que tu vois mon erreur?? Il bloque a un moment donne:
import java.io.*;
class ExecTest
{
public static void main(String[] args)
{
int i;
String cmd;
cmd="";
for(i=0;i<args.length;i++) cmd+=args[i]+" ";
System.out.println(cmd);
cmd+="\n";
try
{
Process p=Runtime.getRuntime().exec("cmd.exe");
ThreadEmptyBuffer t2 = new ThreadEmptyBuffer(p, cmd);
t2.start();
try{
p.waitFor () ;
} catch (InterruptedException intexc) {
System.out.println ("Interrupted Exception on waitfor: " + intexc) ;
}
System.out.println ("Return code from process " + p.exitValue ()) ;
System.out.println ("Done executing") ;
}
catch(Exception ex) { }
}
}
class ThreadEmptyBuffer extends Thread{
public Process process;
public String cmd;
public ThreadEmptyBuffer(Process p, String command){
process = p;
cmd = command;
}
public void run(){
try{
boolean vrai_faux = true;
OutputStream in = process.getOutputStream();
InputStream out=new BufferedInputStream(process.getInputStream());
byte[] b=new byte[1024];
while(vrai_faux){
int n=out.read(b);
for(int i=0;i<n;i++) System.out.print((char)b[i]);
in.write(cmd.getBytes());
if (!(in.equals(null))){
in.flush();
}else vrai_faux = false;
in = process.getOutputStream();
}
} catch(IOException e){
System.out.println ("erreur d'IO=" +e) ;
}
process.notifyAll();
}
}
-----Message d'origine-----
De : Guillaume Desnoix [mailto:[EMAIL PROTECTED]]
Envoye : jeudi 4 juillet 2002 11:39
A : [EMAIL PROTECTED]
Objet : Re: WAITFOR ???
Fabien Lonardi:
> Et tu fais comment pour vider le flux alors qu'il est en attente?? C la
> question que je pose depuis un ou deux jours????
Deux possibilites:
1) Avant le waitFor(), tu lances deux threads separes (out et err) qui
bouclent en lecture sur les flux du process.
2) Tu n'appelles pas waitFor(). Tu boucles en lecture sur les deux flux.
Lorsqu'ils sont fermes, tu appelles waitFor();
Guillaume