How to output the ant.exec() result to console?

(Maxim Neaga) #1

Suppose I have a helloworld.php file that does a simple

echo ‘Hello World!’;

then I have a gradle task

task hello << {

ant.exec(executable: ‘php’) {

arg(value: ‘helloworld.php’)



When I run

gradle hello

I’m just getting the “BUILD SUCCESSFUL” output. How can I get the “Hello World” output as well?

Thank you in advance!

(Peter Niederwieser) #2

First of all, why aren’t you using an ‘Exec’ task instead?

(Maxim Neaga) #3

I was trying something like

task hello(type:Exec) {

commandLine ‘php helloworld.php’


But I was getting error:

A problem occurred starting process ‘command ‘php helloworld.php’’

Not sure how to do it the right way. Unfortunately I didn’t find examples on how to do it in the documentation.

(Peter Niederwieser) #4

I think it should be ‘commandLine ‘php’, ‘helloworld.php’’. For an example, see ‘Exec’ in the Gradle Build Language Reference.

(Maxim Neaga) #5

Thank you! What made me confused is the following statement in the documentation:


The full command line, including the executable plus its arguments.

I thought both executable and arguments were supposed to go together.

Thanks again!

(Konrad Garus) #6


I do need answer to the same question. And to answer you question - I do need ant.exec because Exec doesn’t resume until the process finishes.

(Maxim Neaga) #7


You can use the following:

ext ['cmd'] = 'php helloworld.php'
exec {
    commandLine 'sh', '-c', cmd

(Konrad Garus) #8

Thanks, but I have one more requirement here: I need to spawn another process and not wait for it to finish.

The use case is integration testing. I want to start the server, run my integration tests, then stop the server. Obviously I can’t wait for the server to exit before I run the tests. :slight_smile:

(Luke Daley) #9

I’d use plain Java ProcessBuilder in this case.