batch-file - 如何将参数从 gradle exec 任务传递到命令行

标签 batch-file gradle sh build.gradle command-line-arguments

我正在尝试使用 gradle exec 任务连接一个 bat 和 sh 文件(取决于正在运行的操作系统)。但我无法弄清楚如何从 exec 任务向 bat/sh 发送参数。

task testing(type:Exec) {
    workingDir '.'

    if (System.properties['os.name'].toLowerCase().contains('windows')) {
        if ( project.hasProperty("arg1") ) {
            println arg1
            args arg1
            commandLine 'cmd', '/c', 'run.bat'
        }else{
            commandLine 'cmd', '/c', 'run.bat'
        }
   }else {
        if ( project.hasProperty("arg1") ) {
            args arg1
            commandLine './run.sh'
        }else{
            commandLine './run.sh'
        }
   }
}

如果我将此任务运行为:gradle testing -Parg1=test , 在 println arg1 ,它打印测试

但是我如何将此测试作为参数传递给 bat/sh 文件。

最佳答案

通过 commandLine 传递 arg

视窗

commandLine 'cmd', '/c', 'run.bat' ,arg1

Linux/mac
commandLine './run.sh' , arg1

关于batch-file - 如何将参数从 gradle exec 任务传递到命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47929483/

相关文章:

batch-file - 批处理 - 用户输入的颜色

java - 尝试从 Jhipster 项目获取 war 文件

java - 从 GIT 添加模块到 Android Studio 抛出 "buildToolsVersion is not specified"错误

bash - 在 sh shell 上使用 <<< 会引发错误,而不是在 bash 中

batch-file - 批处理文件,创建编号列表

python - 并行运行 Python 脚本并等待所有脚本完成,然后再执行更多并行脚本

batch-file - 批处理cmd不接受重定向符号

gradle - gradle 中的 sl4j 版本与 Storm 1.0.1 和 elasticsearch 5.2 冲突

bash - 从字符串中正确读取引用/转义的参数

Linux - 如何在删除文件名中的模式时批量重命名文件