Java Runtime.Exec() Guide Java Runtime.Exec () Guía
Everything you ever wanted to know and should know about Java Runtime.exec(). Todo lo que usted siempre quiso saber y debe saber acerca de Java Runtime.exec ().
This old but still golden Este viejo, pero todavía Oro article artículo is an excellent guide to using Runtime.exec(). es una excelente guía para usar Runtime.exec (). The key points he discusses are: Los principales puntos que se analizan son los siguientes:
1. You need to drain the input stream to prevent because failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock. Usted necesita para drenar el flujo de entrada para evitar el fracaso, porque para escribir rápidamente el flujo de entrada o leer la secuencia de salida del subproceso puede causar el subproceso de bloquear, e incluso estancamiento.
2. Use waitFor() instead of exitValue() when you want to wait for the process to finish. Use waitFor () en lugar de exitValue () cuando se quiere esperar a que el proceso hasta el final.
3. Runtime.exec() wouldn’t directly execute shell commands like dir / ls, copy / cp etc. You need to invoke the shell cmd.exe / bash / sh and pass the shell commands. Runtime.exec () no ejecutar directamente los comandos shell como dir / ls, copy / cp etc necesidad de invocar el shell cmd.exe / bash / sh y pasar comandos de la shell. For example in windows your command array to execute dir would be as follows: Por ejemplo, en las ventanas de su comando conjunto para ejecutar dir sería la siguiente:
cmd[0] = “cmd.exe” ; cmd [0] = "cmd.exe";
cmd[1] = “/C” ; cmd [1] = "/ C";
cmd[2] = “dir”; cmd [2] = "dir";
Personally I have successfully used Runtime.exec() on several occasions. Personalmente he utilizado con éxito Runtime.exec () en varias ocasiones. Any C programmer should quickly find equivalence with fork and system calls in C language. Cualquier programador de C debe encontrar rápidamente la equivalencia con un tenedor y llamadas al sistema en lenguaje C. As always RTFM. Como siempre, RTFM.
Filed under Filed under Headline News Headline News , How To Cómo , J2EE , Java Software El software de Java , Programming Programación , Tech Note Nota técnica | |
| |
RSS 2.0 RSS 2,0 | |
Trackback this Article | este artículo |
Email this Article Enviar artículo
You may also like to read También puede leer |




June 9th, 2008 at 10:23 pm Junio 9, 2008 a 10:23 pm
Hi all , Hola a todos,
How to execute the mysql command in linux using the runtime.exec. Cómo ejecutar el comando mysql en linux utilizando el runtime.exec.
example : ejemplo:
String []cmds_slave1={ String [] = (cmds_slave1
“/bin/sh”,”mysql test”, "/ Bin / sh", "mysql test",
}; );
p3=Runtime.getRuntime().exec(cmds_slave1); p3 = Runtime.getRuntime (). exec (cmds_slave1);
BufferedReader pr = new BufferedReader(new InputStreamReader(p3.getInputStream())); BufferedReader pr = new BufferedReader (nuevo InputStreamReader (p3.getInputStream ()));
System.out.println(”after buFFer stmt”); System.out.println ( "después de amortiguación stmt");
String x1; String X1;
while ((x1 = pr.readLine()) != null) while ((x1 = pr.readLine ())! = null)
{ (
System.out.println(x1 + ” from mysqllll…”); System.out.println (x1 + "de mysqllll…");
} )
}catch(Exception e) ) capturas (Exception e)
{ (
e.printStackTrace(); e.printStackTrace ();
} )
p3.waitFor(); p3.waitFor ();
But i am not getting any output. Pero no estoy recibiendo ninguna salida.
Please let me know how to proceed more. Por favor, hágamelo saber cómo proceder.
Thanks In Advance. Gracias de antemano.
Prakash