Results 1 to 7 of 7
- 03-23-2011, 06:23 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
Invoke external program using ProcessBuilder
Hello,
I am trying to invoke an external program using ProcessBuilder. It seems pretty straight forward so I implemented some code to perform the task. But somehow the program is terminated without performing the specified task. The ProcessBuilder supposedly throws an exception if something is wrong but it didn't throw any exception and is just finished.
Java Code:List<String> command=new ArrayList<String>(); command.add(ExecPath); try { ProcessBuilder pb = new ProcessBuilder(command); Map<String, String> env = pb.environment(); pb.directory(new File(workdir)); } catch (IOException e) { [INDENT]e.printStackTrace(); return false;[/INDENT] }
- 03-23-2011, 06:49 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Because you haven't actually started the process.
- 03-23-2011, 07:23 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
I accidentally delete those part when posting the thread. But it's there.
Java Code:try { ProcessBuilder pb = new ProcessBuilder(command); Map<String, String> env = pb.environment(); pb.directory(new File(workdir)); final Process process =pb.start(); } ...
- 03-23-2011, 07:29 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
You haven't told the program to wait for the process to finish. See the API docs for Process.
- 03-23-2011, 07:33 AM #5
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
- 03-23-2011, 07:56 AM #6
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
- 03-23-2011, 09:42 AM #7
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
How Can I Set The Position Of External Program?
By *Java* in forum New To JavaReplies: 5Last Post: 03-14-2011, 10:33 AM -
How to invoke a C API using Java program
By mgopi in forum New To JavaReplies: 6Last Post: 12-27-2008, 12:17 PM -
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 -
Use a external file in my program
By romina in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:28 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks