简体   繁体   中英

Groovy AntBuilder Execute task in Background

Could use your help:

Trying to execute an ant task in Groovy so that it doesn't wait for the response from the script (ie run in background)

I've tried the following two ways with no success

//Cannot find script
ant.exec(failonerror: "true", executable: "scriptname.sh &") 

// Says: You have used an attribute or nested element which is not compatible with spawn 
ant.exec(failonerror: "true", spawn:"true", executable: "scriptname.sh") 

Any advice on how to accomplish this? I've searched google but can't find any good examples for Groovy.

Thanks guys, I appreciate the help.

script.sh

#!/bin/bash

cat > foo.conf << EOF
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
    ServerName localhost
</VirtualHost>
EOF

build.gradle

task external << {
    ant.exec(spawn:'true', executable: "${project.projectDir}/script.sh") 
}

build.gradle and script.sh must be located in the same folder in this solution. You need to provide full path to executable .

Instead of trying to figure out how to do this in AntBuilder where there is limited documentation, I created a second shell script that executed the desired shell script in the background instead.

#!/bin/bash

command="./scriptname.sh  $1 $2 $3 $4"

nohup $command > /dev/null 2>&1 &

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM