How to run a java program in a separate process using GUI button?

Discussion in 'Java' started by misbah.mubarak@gmail.com, Mar 9, 2007.

  1. Guest

    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.
     
    , Mar 9, 2007
    #1
    1. Advertising

  2. Guest

    On 9 mar, 14:53, 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 process
    variables?

    You could use System.err to get the println statements displayed. No?

    gethostbyname
     
    , Mar 9, 2007
    #2
    1. Advertising

  3. Guest

    On 9 mar, 14:53, 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
     
    , Mar 9, 2007
    #3
  4. Guest

    On 9 mar, 14:53, 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" the
    output 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(new
    InputStreamReader(in));
    while ((linha = entrada.readLine()) != null) {
    System.out.println(linha);
    }
    entrada.close();

    process = new ProcessBuilder(command);
    process.start();
    }

    catch(Exception except)
    {
    except.printStackTrace();
    }

    }
    }
    ********

    gethostbyname
     
    , Mar 9, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. EvgueniB
    Replies:
    1
    Views:
    674
    Anthony Borla
    Dec 15, 2003
  2. Frank Fredstone
    Replies:
    1
    Views:
    469
    Jean-Francois Briere
    Jun 27, 2006
  3. Replies:
    7
    Views:
    462
  4. KevinSimonson
    Replies:
    7
    Views:
    367
    Screamin Lord Byron
    Oct 18, 2010
  5. Yesterday Paid
    Replies:
    1
    Views:
    294
    Dave Angel
    Jun 21, 2012
Loading...

Share This Page