This question already has an answer here:
Is there a way to run this command line within a Java application?
java -jar map.jar time.rel test.txt debug
I can run it with command but I couldn't do it within Java.
|
This question already has an answer here: Is there a way to run this command line within a Java application?
I can run it with command but I couldn't do it within Java. |
|||||||||
marked as duplicate by Jarrod Roberson Sep 8 '15 at 16:19This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. |
|||||||||
|
|||||||||
http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html |
|||||||||||||||||||||
|
|
You can also watch the output like this:
And don't forget, if you are running in Windows, you need to put "cmd /c " in front of your command. |
||||
|
To avoid the called process to be blocked if it outputs a lot of data on the standard output and/or error, you have to use the solution provided by Craigo. Note also that ProcessBuilder is better than Runtime.getRuntime().exec(). This is for a couple of reasons: it tokenizes better the arguments, and it also takes care of the error standard output (check also here).
I use a new function "watch" to gather this data in a new thread. This thread will finish in the calling process when the called process ends.
|
||||
|
|
Consider the following if you run into any further problems, but I'm guessing that the above will work for you: |
|||
|
|
|
|||
|
|
|
Have you tried the exec command within the Runtime class?
|
|||
|
|
|
||||
|
|
|
what about
|
|||
|
|