我正在尝试使用 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/