I am writing a custom plugin and tasks which run native commands.
I know how to do this running scripts but I would like to have more direct control.
Here is a short clip from my @TaskAction.
...
when {
OperatingSystem.current().isLinux -> {
project.exec {
commandLine("/bin/bash")
args("-s", "--")
standardInput = """
echo "hello from linux"
""".trimIndent().byteInputStream(Charsets.UTF_8)
}
}
OperatingSystem.current().isWindows -> {
project.exec {
commandLine("start")
args("%comspec%")
standardInput = """
echo "hello from windows"
""".trimIndent().byteInputStream(Charsets.UTF_8)
}
}
else ->
logger.error("unknown OS family ${OperatingSystem.current()}")
}
...
What would be appropriate values for the commandLine and args for running these scripts?
The commands here are short and could easily be run as part of args.
Imagine that these commands are tens of lines and running them as args would be inappropriate.
Yes, Exec ultimately uses ProcessBuilder to execute the process, but not from Instrumented. Instrumented as the name suggests is for instrumented code on the build script class path to detect configuration cache inputs. It has nothing to do with Exec.
An OS specific shell would not really make much sense. Exec is about executing some executable, not about interpreting an OS specific shell script.
And to execute “some executable”, you have to specify which one you want to have executed, so there is no default value.