gradle:执行任务"type:Exec";带有许多带有空格的参数 [英] gradle: Execute task "type:Exec" with many arguments with spaces

查看:537
本文介绍了gradle:执行任务"type:Exec";带有许多带有空格的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有应在Windows操作系统上创建Websphere配置文件的gradle任务

I have the gradle task that should create Websphere profile on Windows OS

task createProfile(type:Exec) {

    def commandToExecute = new StringBuffer()
    def profile = 'AppSrv02'
    def wasHome = 'C:/IBM new/WebSphere/AppServer'

    def str = new LinkedList <String> ();
    str.add('cmd')
    str.add('/c')
    str.add(wasHome + '/bin/manageprofiles.bat')
    str.add('-create')
    str.add('-profileName')
    str.add(profile)
    //str.add('-templatePath')
    //str.add(wasHome + '/profileTemplates/default')

    println (str)
    commandLine str.toArray()

}

如果我取消注释行,在任务失败并说:"C:/IBM"不是有效的批处理文件之后,就会出现问题.如果我未将profileTemplates放在包含空格的文件夹中,则一切将再次正常运行.但是模板应该位于int wasHome(有时wasHome包含空格(

And the problem appears if I uncomment commented lines, after it task fails and say me that: "C:/IBM" is not valid batch file. If I put profileTemplates not in the folder that contains spaces, everything works fine again. But templates should lies int wasHome( And sometimes wasHome has spaces(

我现在有了想法,为什么添加带有空格的值的模板键会影响Gradle尝试启动"C:/IBM"而不是指定为"C:/IBM new/WebSphere/AppServer/bin/manageprofiles.bat" .似乎是java.lang.ProcessBuilder内部的问题.

I have, now ideas why adding templates key with value with spaces influence in such way that Gradle tries to start "C:/IBM" instead specified 'C:/IBM new/WebSphere/AppServer/bin/manageprofiles.bat'. It seems that, possibly, problem inside java.lang.ProcessBuilder.

我尝试通过添加 "/"" 来引用路径,但是没有任何效果((((不足为奇,因为ProcessBuilder暗示了如果需要的话,可以自行引用.

I tries to quote paths, by adding "/"" but nothing works(((( what isn't surprise, because ProcessBuilder implies quoting by itself if it is needed.

所以,我问是否有人遇到类似的问题,并且可以建议如何解决此问题?提前致谢.

So, I am asking if anybody had the similar problem and could recommend how to work around this issue? Thanks in advance.

推荐答案

如果有人需要它,我们找到了解决此问题的方法.任务最终看起来像:

If somebody needed it, we found a workaround for this problem. The task finally looks like:

task createProfile(type: Exec) {
    executable = new File(wsadminLocation, manageProfilesFileName)
    def templatePath = wasHome + File.separator + "profileTemplates" + File.separator + "default"
    def argsList = ["-create", "-profileName", profile, "-templatePath", templatePath, "-nodeName", nodeName, "-cellName", wasCellName, "-enableAdminSecurity", isProfileSecured, "-adminUserName", rootProject.wasLogin, "-adminPassword", rootProject.wasPassword]
    args = argsList
}

基本思想是将参数传递给Gradle的不是长字符串,而是列表.因此,如果参数包含空格,则不会有任何问题.

The basic idea is to pass the arguments to the Gradle not as long string, but as a list. So in this way there aren't any problems if an argument contains a space.

这篇关于gradle:执行任务"type:Exec";带有许多带有空格的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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