|
|
How to run a java program in a separate process using GUI button?
I want to run a java program using a button on the GUI. I have usedthe following codetry{ System.out.println("Inside execution"); Runtime.getRuntime().exec("cmd.exe"); System.out.println(command); process= new ProcessBuilder(command); process.start();}catch(Exception except){except.printStackTrace();}The purpose is to launch a separate execution window a part from thecmd.exe thats open through the GUI. When I did this using processbuilder,the output would come but not in a separate execution window.Moreover, the output was not complete and the println statements werenot getting displayed.
|
|
0
|
|
|
|
Reply
|
misbah.mubarak (1)
|
3/9/2007 5:53:35 PM |
|
On 9 mar, 14:53, misbah.muba...@gmail.com wrote:> I want to run a java program using a button on the GUI. I have used> the following code> try{> System.out.println("Inside execution");> Runtime.getRuntime().exec("cmd.exe");> System.out.println(command);> process= new ProcessBuilder(command);> process.start();}>> catch(Exception except)> {> except.printStackTrace();}>> The purpose is to launch a separate execution window a part from the> cmd.exe thats open through the GUI. When I did this using process> builder,the output would come but not in a separate execution window.> Moreover, the output was not complete and the println statements were> not getting displayed.Please, post your complete code. What about command and processvariables?You could use System.err to get the println statements displayed. No?gethostbyname
|
|
0
|
|
|
|
Reply
|
gethostbyname
|
3/9/2007 7:42:47 PM
|
|
On 9 mar, 14:53, misbah.muba...@gmail.com wrote:> I want to run a java program using a button on the GUI. I have used> the following code> try{> System.out.println("Inside execution");> Runtime.getRuntime().exec("cmd.exe");> System.out.println(command);> process= new ProcessBuilder(command);> process.start();}>> catch(Exception except)> {> except.printStackTrace();}>> The purpose is to launch a separate execution window a part from the> cmd.exe thats open through the GUI. When I did this using process> builder,the output would come but not in a separate execution window.> Moreover, the output was not complete and the println statements were> not getting displayed.You could use System.err to get the println statements displayed.gethostbyname
|
|
0
|
|
|
|
Reply
|
gethostbyname
|
3/9/2007 7:46:08 PM
|
|
On 9 mar, 14:53, misbah.muba...@gmail.com wrote:> I want to run a java program using a button on the GUI. I have used> the following code> try{> System.out.println("Inside execution");> Runtime.getRuntime().exec("cmd.exe");> System.out.println(command);> process= new ProcessBuilder(command);> process.start();}>> catch(Exception except)> {> except.printStackTrace();}>> The purpose is to launch a separate execution window a part from the> cmd.exe thats open through the GUI. When I did this using process> builder,the output would come but not in a separate execution window.> Moreover, the output was not complete and the println statements were> not getting displayed.I think I understood your problem now. Would you like "redirect" theoutput stream of external process?********package javaapplication2;import java.awt.*;import java.io.*;import javax.swing.*;/** * * @author gethostbyname */public class Main { public Main() { } /** * @param args the command line arguments */ public static void main(String[] args) { ProcessBuilder process; try{ String command = "c:\\WINDOWS\\system32\\rasdial.exe"; InputStream in =Runtime.getRuntime().exec(command).getInputStream(); String linha; BufferedReader entrada = new BufferedReader(newInputStreamReader(in)); while ((linha = entrada.readLine()) != null) { System.out.println(linha); } entrada.close(); process = new ProcessBuilder(command); process.start(); } catch(Exception except) { except.printStackTrace(); } }}********gethostbyname
|
|
0
|
|
|
|
Reply
|
gethostbyname
|
3/9/2007 8:29:57 PM
|
|
|
3 Replies
410 Views
(page loaded in 0.065 seconds)
|
|
|
|
|
|
|
|
|