如何在 sbt 中使用 fullRunTask 分叉进程? [英] How to fork process with fullRunTask in sbt?
问题描述
我正在编写一个从 sbt 启动服务器的 sbt 插件.
I'm writing a sbt plugin that start a server from sbt.
lazy val kstart = taskKey[Unit]("Start scala kata")
lazy val Backend = config("backend")
Seq(
fullRunTask(kstart, Backend, "com.scalakata.backend.Boot", "..."),
fork in kstart := true,
connectInput in kstart := false
)
问题是服务器启动后没有sbt提示
The problem is that after the server is started, I dont have a sbt prompt.
> kstart
[info] Running com.scalakata.backend.Boot _
// no prompt here :(
看起来进程没有fork什么的.
It look like the process did not fork or something.
推荐答案
您在单独的 JVM 中运行您的服务器,您遇到的问题是 sbt 将等待进程退出,然后让您输入任何其他内容.
You're running your server in a separate JVM, the problem you're having is that sbt will wait for the process to exit before letting you type anything else.
相关代码见GitHub.
// fork with Java because Scala introduces an extra class loader (#702)
val process = Fork.java.fork(configLogged, scalaOptions)
def cancel() = {
log.warn("Run canceled.")
process.destroy()
1
}
val exitCode = try process.exitValue() catch { case e: InterruptedException => cancel() }
调用 process.exitValue()
将阻塞,直到进程存在.
The call process.exitValue()
will block until the process exists.
如果你想让它在后台运行,我认为你必须自己控制这个过程.
I think you'll have to control the process by yourself if you want it to run in the background.
这篇关于如何在 sbt 中使用 fullRunTask 分叉进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!