从Gradle运行后台作业

编程入门 行业动态 更新时间:2024-10-22 21:17:42
本文介绍了从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运行后台作业

本文发布于:2023-11-27 09:23:46,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:作业   后台   Gradle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!