hola:
alguien me puede decir como usar Process.getOutputStream() para responder a comando ejecutado desde CMD de windows como por ejemplo el comando DATE que despues de ejecutado muestra la fecha actual y espera a que se ingrese la fecha nueva.
este es parte del codigo que llevo hecho... puedo leer mas no escribir
alguien me puede decir como usar Process.getOutputStream() para responder a comando ejecutado desde CMD de windows como por ejemplo el comando DATE que despues de ejecutado muestra la fecha actual y espera a que se ingrese la fecha nueva.
este es parte del codigo que llevo hecho... puedo leer mas no escribir
Código [Seleccionar]
class ejecutar implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
String texto = texto1.getText();
Runtime rt = Runtime.getRuntime();
//String[] texto = {"date"};
try
{
// Se lanza el ejecutable.
Process p = rt.exec("cmd /c " + texto);
p.waitFor();
// Se obtiene el stream de salida del programa
InputStream is = p.getInputStream();
InputStream er = p.getErrorStream();
OutputStream sal = p.getOutputStream();
// int wait = p.waitFor();
// Se prepara un bufferedReader para poder leer la salida más
// comodamente.
BufferedReader br = new BufferedReader (new InputStreamReader (is));
BufferedReader br2 = new BufferedReader (new InputStreamReader (er));
// Se lee la primera linea
String aux = br.readLine();
String aux2 = br2.readLine();
// Mientras se haya leido alguna linea
while (aux!=null)
{
// Se escribe la linea en pantalla
areaTexto1.append(aux + newline);
areaTexto1.setCaretPosition(areaTexto1.getDocument().getLength());
texto1.setText("");
// y se lee la siguiente.
aux = br.readLine();
}
while (aux2!=null)
{
areaTexto1.append(aux2 + newline);
areaTexto1.setCaretPosition(areaTexto1.getDocument().getLength());
texto1.setText("");
aux2 = br2.readLine();
}
}
catch (Exception e)
{
// Excepciones si hay algún problema al arrancar el ejecutable o al
// leer su salida.
e.printStackTrace();
}
}
}