Switch from Runtime.exec() to ProcessBuilder.

This commit is contained in:
Chris Rankin 2017-02-13 12:27:06 +00:00
parent 166cbbf2e5
commit 94747dcddf
5 changed files with 11 additions and 12 deletions

View File

@ -18,16 +18,16 @@ class Explorer(val explorerController: ExplorerController) : AutoCloseable {
return
}
val p = explorerController.execute(
config.explorerDir,
val p = explorerController.process(
"--host=localhost",
"--port=${config.artemisPort}",
"--username=${config.user["user"]}",
"--password=${config.user["password"]}",
"--certificatesDir=${config.ssl.certificatesDirectory}",
"--keyStorePassword=${config.ssl.keyStorePassword}",
"--trustStorePassword=${config.ssl.trustStorePassword}"
)
"--trustStorePassword=${config.ssl.trustStorePassword}")
.directory(explorerDir)
.start()
process = p
log.info("Launched Node Explorer for '{}'", config.legalName)

View File

@ -1,8 +1,6 @@
package net.corda.demobench.model
import tornadofx.Controller
import java.nio.file.Path
import java.nio.file.Paths
class ExplorerController : Controller() {
@ -13,7 +11,7 @@ class ExplorerController : Controller() {
log.info("Explorer JAR: $explorerPath")
}
internal fun execute(cwd: Path, vararg args: String) = jvm.execute(explorerPath, cwd, *args)
internal fun process(vararg args: String) = jvm.processFor(explorerPath, *args)
fun explorer() = Explorer(this)

View File

@ -18,8 +18,8 @@ class JVMConfig : Controller() {
return arrayOf(javaPath.toString(), "-jar", jarPath.toString(), *args)
}
fun execute(jarPath: Path, cwd: Path, vararg args: String): Process {
return Runtime.getRuntime().exec(commandFor(jarPath, *args), null, cwd.toFile())
fun processFor(jarPath: Path, vararg args: String): ProcessBuilder {
return ProcessBuilder(commandFor(jarPath, *args).toList())
}
}

View File

@ -18,7 +18,9 @@ class WebServer(val webServerController: WebServerController) : AutoCloseable {
return
}
val p = webServerController.execute(config.nodeDir)
val p = webServerController.process()
.directory(nodeDir)
.start()
process = p
log.info("Launched Web Server for '{}'", config.legalName)

View File

@ -1,7 +1,6 @@
package net.corda.demobench.model
import tornadofx.Controller
import java.nio.file.Path
class WebServerController : Controller() {
@ -12,7 +11,7 @@ class WebServerController : Controller() {
log.info("Web Server JAR: $cordaPath")
}
internal fun execute(cwd: Path) = jvm.execute(cordaPath, cwd, "--webserver")
internal fun process() = jvm.processFor(cordaPath, "--webserver")
fun webServer() = WebServer(this)