i need to execute a .jar file in command line using java... n i have to take the output obtained from tat file...
How to execute dos commands in java ???
Collapse
X
-
Originally posted by janaki112i need to execute a .jar file in command line using java... n i have to take the output obtained from tat file...
Code:// execute a child process using java exec command and get output import java.io.*; import java.lang.*; public class JavaExec { public static void main (String args[]){ try { // get runtime environment and execute child process Runtime systemShell = Runtime.getRuntime(); Process output = systemShell.exec("java -jar hello.jar"); // open reader to get output from process BufferedReader br = new BufferedReader (new InputStreamReader(output.getInputStream())); String line = null; System.out.println("<OUTPUT/>"); while((line = br.readLine()) != null ) { System.out.println(line); } // display process output System.out.println("</OUTPUT>"); int exitVal = output.waitFor(); // get process exit value System.out.println("Process Exit Value : "+ exitVal); } catch (IOException ioe){ System.err.println(ioe); } catch (Throwable t) { t.printStackTrace();} } }
Comment