Results 1 to 6 of 6
- 08-11-2011, 12:59 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 7
- Rep Power
- 0
Running an bat execution from Java
Hi,
I am trying to execute a .bat file (called startwatch.bat) from Java using the following code:
The text inside startwatch.bat is as follows:Java Code:public static void main(String[]args){ //..... runCmd("startwatch.bat"); //..... } public static void runCmd (String cmd) { String str = null; try { Process p = Runtime.getRuntime().exec(cmd); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); System.out.println("Here is the standard output of the command: " + cmd); while ((str = stdInput.readLine()) != null) { System.out.println(str); } } catch (IOException e) { System.out.println("exception happened - here's what I know: "); e.printStackTrace(); System.exit(-1); } }
This .bat file will run a different java script. Since this new java script will be monitoring my main script, I must have them running at the same time. When I run the main java script, it opens the bat file executing as planned. However, it does not allow the main java script to continue, as it is waiting for the termination of the bat file.Java Code:start java -classpath ../KNIME_inputs/bin KNIME_inputs
Is there a way for me to force the main java script to move on, but to also keep the bat file running?
Thanks
- 08-11-2011, 02:25 PM #2
What is the "it" you are referring to? The JVM or the OS?it opens the bat file executing as planned. However, it does not allow the main java script to continue
Where does the "main" program block waiting for completion of called program? You have a loop that would "wait"
Could you put the code that blocks on its own thread?
- 08-11-2011, 03:15 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
And just to add another one -
what happens when you run that BAT file by itself from terminal?
Does it go back to the prompt?
- 08-11-2011, 03:18 PM #4
Member
- Join Date
- Aug 2011
- Posts
- 7
- Rep Power
- 0
Hi Norm,
Can you please explain how I can putthe code that blocks on its own thread?
- 08-11-2011, 03:20 PM #5
Member
- Join Date
- Aug 2011
- Posts
- 7
- Rep Power
- 0
Tolls,
Yes, when I run the BAT file by itself from the terminal it works perfect, executing the code in a separate cmd window and waiting for a new prompt in the original.
- 08-11-2011, 03:47 PM #6
To see how to put a section of code on its own thread, read the tutorial. Go here and Find thread:
The Really Big Index
and/or read the API doc:
Java Platform SE 6
Similar Threads
-
Query about JAVA Program Execution
By annu in forum New To JavaReplies: 2Last Post: 06-15-2011, 01:16 PM -
Re-iterate Thread execution after its execution finishes.
By TurtleRock in forum New To JavaReplies: 10Last Post: 11-29-2010, 02:02 PM -
Script execution from java
By umapathy_sekar in forum Advanced JavaReplies: 7Last Post: 09-17-2010, 05:34 PM -
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 -
Need help in java program execution...
By sachinmittal in forum New To JavaReplies: 6Last Post: 10-10-2008, 02:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks