Read name of NativeExecutableBinary

I’d like to create a task, which would do some action after compilation of a C binary:

task doSomethingWithExeFile {
 println executableFile
}
doSomethingWithExeFile.finalizedBy build

Why executableFile is not recognized?

finalizedBy Returns tasks that finalize this task.

I think you might want…

build.finalizedBy doSomethingWithExeFile

…or…

doSomethingWithExeFile.mustRunAfter build

Thanks Richard for replay, however all your proposals don’t run after build, but before it.
I also forgot about binaries.all in my example, so it cause an additional issue.

According to Richard’s suggestion I tried two new ways:

task doSomethingWithExeFile { binaries.all { println executableFile } } //doSomethingWithExeFile.finalizedBy build //1st - my old one //build.finalizedBy doSomethingWithExeFile //2th //doSomethingWithExeFile.mustRunAfter build //3th

all runs before the build. What do I do wrongly?

Finally I’ve managed to do it with doLast {} inside of the task. Why do I need it if I have already finalizedBy?