Results 1 to 5 of 5
  1. #1
    g123456 is offline Member
    Join Date
    Dec 2009
    Posts
    34
    Rep Power
    0

    Default Problem with running an external program via java

    Java Code:
    import java.io.*;
    import java.util.*;
    
    
    public class execute {
          
    	
    		//main method
    	public static void main(String[] args) 
    	{ 
     
         try
         {
         
          Runtime rt = Runtime.getRuntime() ;
    
          Process p = rt.exec("duck.exe") ;
          }
          catch(IOException e)
          {
    	      
    	      
          }
    
         
          
          
      }
      
    }

    duck.exe is in the same folder with the java class

    no compile errors, no execution errors

    but the problem is that it opens it in the backround. is there some way to make execute it on the desktop and not in the background?

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    I'm not sure what is meant by on the desktop, an application launched by Java runtime will show up on the desktop of the current user if it is a graphical desktop application. Do you mean, to make it execute in a way that causes the Java application to launch it to wait for it to finish ?

    The Runtime.exec() facility is now deprecated, prefering the ProcessBuilder facility now instead.

    Java Code:
    ProcessBuilder builder = new ProcessBuilder("duck.exe");
    Process process = builder.start();
    int result = process.waitFor();
    Where exception handling has been omitted for clarity here.

    The process builder allows you to set up input and output streams, to allow your java application to interact with the child process, and allows you to set up the working directory, and environment variables to be present in the child process execution context.

    But more immedately, it that Process object has that waitFor() method to allow the calling Java thread to block until the child process completes.

  3. #3
    g123456 is offline Member
    Join Date
    Dec 2009
    Posts
    34
    Rep Power
    0

    Default

    no what i mean is that the program duck.exe is being executed in the background i want it to be executed on the current user instead

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,353
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by travishein View Post
    The Runtime.exec() facility is now deprecated, prefering the ProcessBuilder facility now instead.
    According to my documentation (Java version 1.6) it isn't deprecated (yet).

    kind regards,

    Jos

  5. #5
    g123456 is offline Member
    Join Date
    Dec 2009
    Posts
    34
    Rep Power
    0

    Default

    i think its fixed but i got now a new problem that i will post it in another topic!

Similar Threads

  1. Replies: 0
    Last Post: 08-26-2009, 01:03 PM
  2. Execute external program from java
    By ankitmcgill in forum New To Java
    Replies: 1
    Last Post: 06-01-2009, 03:58 AM
  3. Executing an external java program
    By arunsubramanian in forum Advanced Java
    Replies: 5
    Last Post: 02-06-2009, 07:49 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •