从Gradle运行后台作业 [英] Run a background job from Gradle

查看:141
本文介绍了从Gradle运行后台作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个启动远程作业的任务,如

 任务mytask(类型:Exec){
commandLine'ssh'
args'-f -l me myserver ./start'.split('')
}

并且它可以工作,但是,它似乎等待工作终止。但它永远不会终止,它不应该。



从命令行执行相同的操作:由于 -f 切换 ssh 命令在后台执行。



我试着添加'>&'/ dev / null (csh stdout和stderr重定向)到命令行,但没有任何成功。另外,明显的& 什么都没做。我也提取了命令行到一个脚本,它总是一样的:Gradle等待终止。



解决方案



我已经通过使用脚本解决了这个问题,并在脚本中重定向了stdout和stderr。我的问题来自混淆重定向...通过传递'>&'/ dev / null 我重定向了远程计算机上的流,但是需要重定向(即,不要将重定向操作符放在引号中)。

解决方案 Exec 任务总是等待终止。要运行后台作业,您需要编写自己的任务,例如,可以使用Java ProcessBuilder API。


I've created a task starting a remote job like

task mytask(type: Exec) {
    commandLine 'ssh'
    args '-f -l me myserver ./start'.split(' ')
}

and it works, however, it seems to wait for the job to terminate. But it never terminates and it shouldn't.

Doing the same from the command line works: Because of the -f switch the ssh command gets executed in the background.

I've tried to add '>&' /dev/null (csh stdout and stderr redirect) to the command line, but without any success. Also the obvious & did nothing. I also extracted the command line into a script, and it's always the same: Gradle waits for termination.

Solution

I've solved it by using a script and redirecting both stdout and stderr in the script. My problem came from confusing redirections... by passing '>&' /dev/null I redirected the streams on the remote computer, but what was needed was a redirection on the local one (i.e., without putting the redirection operator in quotes).

解决方案

The Exec task always waits for termination. To run a background job, you need to write your own task, which could, for example, use the Java ProcessBuilder API.

这篇关于从Gradle运行后台作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆