繁体   English   中英

在PlayFramework 2中使用scala.sys.process

[英]Using scala.sys.process in playframework 2

我正在尝试通过网络允许其他用户访问某些本地系统服务。

经过一番谷歌搜索后,我最终选择使用Play框架作为前端来接受Web服务调用。 收到呼叫后,Play将通过powershell执行一些命令。 例如,

在我的Application.scala中

def test = Action {
    println(Seq("powershell.exe", "dir", "c:").!)
    Ok("")
}

对应的路线信息是

GET      /test     controllers.Application.test

我的问题是,尽管对powershell的调用结果被打印出来,但该方法永远不会返回。 从客户端(浏览器)的角度来看,它只是持续等待对... / test的调用返回。

我已经测试了代码本身,并且运行良好。 我的问题似乎仅在通过Play运行时出现。

任何建议深表感谢!

ProcessBuilder scaladoc:

abstract def !(log: ProcessLogger): Int
    Starts the process represented by this builder, blocks until it exits, 
    and returns the exit code.

尝试改用lines -它会返回一个Stream

编辑

如果命令已经完成,您是否还没有从流中读取命令的输出? 之后,只需手动从其他流中调用Process.destroy() 创建一个演员,并从解析Stream线程向他发送消息,它将关闭进程。 或使用CountDownLatch等待,这是一种更Java的方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM