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!
First of all, why aren’t you using an ‘Exec’ task instead?
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.
I think it should be ‘commandLine ‘php’, ‘helloworld.php’’. For an example, see ‘Exec’ in the Gradle Build Language Reference .
Thank you! What made me confused is the following statement in the documentation:
commandLine
The full command line, including the executable plus its arguments.
I thought both executable and arguments were supposed to go together.
Thanks again!
Hello,
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.
Konrad,
You can use the following:
ext ['cmd'] = 'php helloworld.php'
exec {
commandLine 'sh', '-c', cmd
}
1 Like
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.
luke_daley
(Luke Daley)
February 10, 2014, 11:15pm
9
I’d use plain Java ProcessBuilder in this case.