Results 1 to 5 of 5
- 12-30-2009, 03:26 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 34
- Rep Power
- 0
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?
- 12-30-2009, 04:27 PM #2
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.
Where exception handling has been omitted for clarity here.Java Code:ProcessBuilder builder = new ProcessBuilder("duck.exe"); Process process = builder.start(); int result = process.waitFor();
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.
- 12-30-2009, 04:44 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 34
- Rep Power
- 0
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
- 12-30-2009, 05:00 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 12-30-2009, 05:06 PM #5
Member
- Join Date
- Dec 2009
- Posts
- 34
- Rep Power
- 0
Similar Threads
-
Problem in running Java swing wizard in jre 1.6 while it is running in jre 1.4
By Sanjay Dwivedi in forum AWT / SwingReplies: 0Last Post: 08-26-2009, 01:03 PM -
Execute external program from java
By ankitmcgill in forum New To JavaReplies: 1Last Post: 06-01-2009, 03:58 AM -
Executing an external java program
By arunsubramanian in forum Advanced JavaReplies: 5Last Post: 02-06-2009, 07:49 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks