Reputation: 133
I'm trying to hook up a bat and sh file (depending on the OS being run on) with the gradle exec task. But I'm unable to figure out how to send an argument to bat/sh from the exec task.
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'
}
}
}
If I run this task as : gradle testing -Parg1=test
, in println arg1
, it prints test
But how do I pass on this test as argument to the bat/sh file.
Upvotes: 5
Views: 6739
Reputation: 5379
pass the arg via the commandLine
Windows
commandLine 'cmd', '/c', 'run.bat' ,arg1
Linux / mac
commandLine './run.sh' , arg1
Upvotes: 11