0

Could use your help:

Trying to execute an ant task in Groovy so that it doesn't wait for the response from the script (i.e. 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.

dsolimano
  • 8,870
  • 3
  • 48
  • 63
abeauchamp
  • 825
  • 2
  • 18
  • 29

2 Answers2

1

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.

Opal
  • 81,889
  • 28
  • 189
  • 210
  • I'm not particularly familiar with gradle unfortunately, and my system architecture is fairly advanced with mounted drives housing the shell scripts. I tried simplifying my solution by writing a second shell script to accomplish it and it worked. I appreciate you taking the time to answer. – abeauchamp Jun 26 '14 at 01:37
0

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 &
abeauchamp
  • 825
  • 2
  • 18
  • 29