xml - Java: how to check if a program has been correctly launched? -
i developping little java jar application storage data in file.xml using basex server. @ beginning, before main program starts, need basex server correctly launched , activated. here do:
runtime runtime = runtime.getruntime(); if (iswindows(os)) { process server = runtime.exec("cmd /c basexserver.bat"); system.out.println(server.waitfor()); } else { if (islinux(os)) { runtime.exec("basexserver"); } }
to check if basexserver correctly running have tried check value returned waitfor method , if value equal 0 command executed while if returned value greater 0 error has occurred. problem method returns 1 command "basexserver.bat" correct. why?
if process goes background after start, can check exitvalue()
zero. secondly can attache error , standard outputs methods geterrorstream()
, getinputstream()
. , monitor them error messages. have @ stream gobbler pattern also, useful. process can stuck if it's output not consumed.
https://docs.oracle.com/javase/7/docs/api/java/lang/process.html http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html
Comments
Post a Comment