Executar algumacoisa.bat

2 respostas
D

Como faço para executar um programa externo a java, por exemplo, executar autoexec.bat a partir do java.

em c++ system(“c:\autoexec.bat”);

i em java?

2 Respostas

R

Hoje, ja saiu uma pergunta quase igual, e a resposta exatamente igual… :slight_smile:

Runtime.getRuntime.exec(“comando”);

[]'s

J

Tente usar este trecho de código

BufferedReader in = null;

try {

Runtime r = Runtime.getRuntime ();

Process p = r.exec ( c:\autoexec.bat);
if ( p != null ) {
in = new BufferedReader ( new InputStreamReader ( p.getInputStream () ) );
    String linha = "";
 
while ( ( linha = in.readLine () ) != null  ) {
       System.out.println (linha);
}
 in.close ();
}

}

catch ( IOException ioe ) { }

Johnny

Criado 12 de abril de 2005
Ultima resposta 12 de abr. de 2005
Respostas 2
Participantes 3