DevOps with project.exec

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.

It would be helpful to know what the default values are for things like executable, commandLine, etc.
I am not seeing it in the documentation.

I am not seeing where exec is defined in the source.

There are no default values, what should they be? A random executable to execute?

And why don’t you see where it is defined? You linked the file where it is defined, just use Ctrl+F :wink:

Thanks for the information.

I am presuming that…

… ultimately invokes the Java Runtime.exec() or ProcessBuilder.start().
Which I suspect are called from Runtime: Instrumented.java
and ProcessBuilder: Instrumented.java
If that is the case then the defaults are those of Runtime (Java Platform SE 7 ) or ProcessBuilder (Java Platform SE 7 ).

p.s. I was presuming a OS specific default shell would be run. I now believe that is wrong.

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. :slight_smile: