gpt4 book ai didi

batch-file - gradle:执行任务 "type:Exec",其中包含许多带空格的参数

转载 作者:行者123 更新时间:2023-12-03 09:42:26 24 4
gpt4 key购买 nike

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

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 有空格(

我现在有了想法,为什么添加带有空格的值的模板键会以这样的方式影响 Gradle 尝试启动“C:/IBM”而不是指定“C:/IBM new/WebSphere/AppServer/bin/manageprofiles.bat”。看来,可能是java.lang.ProcessBuilder 内部的问题。

我尝试通过添加 "/"" 来引用路径但没有任何效果(((( 这并不奇怪,因为 ProcessBuilder 意味着在需要时自行引用。

所以,我问是否有人有类似的问题,并可以推荐如何解决这个问题?提前致谢。

最佳答案

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

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,而不是作为长字符串,而是作为列表。因此,如果参数包含空格,则通过这种方式没有任何问题。

关于batch-file - gradle:执行任务 "type:Exec",其中包含许多带空格的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20613244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com