views:

61

answers:

1

Lets say I have 2 individual java applications javaapp1 and javaapp2.
from javaapp1, I am executing a .bat file (which is responsible for starting javaapp2).

javaaap1 and javaapp2 are independent to eachother.

Suppose I am doing it with process.exec or processbuilder.

Now my question is:

  1. What does exitCode means in this case if its not 0.Does it mean that something went wrong in executing batch file or in the code of javaapp2? or both?

  2. Is it possible to capture errors from javaapp2 in javaapp1?If yes: How? Since i am not calling classes of javaapp2 directly.

  3. Is javaapp2 errors and output are to be handled by javaapp1?

+2  A: 
  1. The exitcode will be whatever the other Java application has returned on System#exit() call. If you're executing it through a bat file, you need to ensure that it passes it back correctly.

  2. You can let it write to stdout or stderr, it will then by available by respectively Process#getInputStream() and Process#getErrorStream().

  3. If it contains code to handle the results mentioned by 1) and 2) correctly, then yes.

Related articles:

BalusC
Thanks Balusc,I want to execute the .bat to start javaapp2 and I wanna do other stuffs. I dont wanna know what happened in javaapp2, thats means i don wanna wait for it to complete and then later on do other stuffs.I just want to start the bat and do other stuff? But I dont want it to hamper my javaapp1. How is this possible Balusc.
So you want to "fire-and-forget" it without blocking the currently running application? Execute it in a separate thread using `Runnable`. I'd suggest [`ExecutorService#submit()`](http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html#submit%28java.lang.Runnable%29) for this. See also this tutorial: http://download.oracle.com/javase/tutorial/essential/concurrency/ Also here, you need to ensure that thread finishes properly, else it will in turn block the current application from shutting down.
BalusC
If I use Runnable or ExecutorService#submit() then dont i have to worry about the filling up the buffer?
Which buffer exactly are you talking about? Btw: there is no "or". You use both. Use the one to submit the other. Further, you're going completely offtopic. IMO, this answer has answered your initial question. If you have new questions, just ask a new Question :)
BalusC