Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
misbah.mubarak@gmail.com - 09 Mar 2007 17:53 GMT
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.
gethostbyname@gmail.com - 09 Mar 2007 19:42 GMT
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
[quoted text clipped - 14 lines]
> 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
gethostbyname@gmail.com - 09 Mar 2007 19:46 GMT
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
[quoted text clipped - 14 lines]
> 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
gethostbyname@gmail.com - 09 Mar 2007 20:29 GMT
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
[quoted text clipped - 14 lines]
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.