Java - como usar Process.getOutputStream()

 
Vista:

como usar Process.getOutputStream()

Publicado por Wilmer Rondon (9 intervenciones) el 06/06/2007 22:28:43
hola:

alguien me podria ayudar a usar el metodo Process.getOutputStream() para ingresar datos a un comando ya ejecutado???

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();
}
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:como usar Process.getOutputStream()

Publicado por Tom (1831 intervenciones) el 07/06/2007 12:04:38
¿¿ OutputStream.write() ??
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar