# DevOps with project.exec

**URL:** <https://discuss.gradle.org/t/devops-with-project-exec/43752>\
**Category:** Help/Discuss\
**Created:** [August 25, 2022, 4:23pm UTC](https://discuss.gradle.org/t/devops-with-project-exec/43752 "2022-08-25T16:23:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![phreed](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@phreed](https://discuss.gradle.org/u/phreed)\
**Post date:** [August 25, 2022, 4:23pm UTC](https://discuss.gradle.org/t/devops-with-project-exec/43752/1 "2022-08-25T16:23:57Z")

</div>

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.

```nohighlight
...
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.

---

<div class="post-metadata">

**Author:** ![phreed](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@phreed](https://discuss.gradle.org/u/phreed)\
**Post date:** [August 25, 2022, 5:44pm UTC](https://discuss.gradle.org/t/devops-with-project-exec/43752/2 "2022-08-25T17:44:53Z")

</div>

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.

> <https://github.com/gradle/gradle/blob/master/subprojects/core-api/src/main/java/org/gradle/api/Project.java>

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [August 25, 2022, 11:42pm UTC](https://discuss.gradle.org/t/devops-with-project-exec/43752/3 "2022-08-25T23:42:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [August 25, 2022, 11:43pm UTC](https://discuss.gradle.org/t/devops-with-project-exec/43752/4 "2022-08-25T23:43:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![elanieluis](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/elanieluis/32/9997_2.png) [@elanieluis](https://discuss.gradle.org/u/elanieluis)\
**Post date:** [August 30, 2022, 5:50am UTC](https://discuss.gradle.org/t/devops-with-project-exec/43752/5 "2022-08-30T05:50:43Z")

</div>

Thanks for the information[.](https://cinemahdapk.onl/)

---

<div class="post-metadata">

**Author:** ![phreed](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@phreed](https://discuss.gradle.org/u/phreed)\
**Post date:** [October 6, 2022, 11:33pm UTC](https://discuss.gradle.org/t/devops-with-project-exec/43752/6 "2022-10-06T23:33:09Z")

</div>

I am presuming that…

- [gradle/ExecSpec.java at master · gradle/gradle · GitHub](https://github.com/gradle/gradle/blob/master/subprojects/process-services/src/main/java/org/gradle/process/ExecSpec.java)
- [gradle/Exec.java at master · gradle/gradle · GitHub](https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/java/org/gradle/api/tasks/Exec.java)

… ultimately invokes the Java `Runtime.exec()` or `ProcessBuilder.start()`.  
Which I suspect are called from [Runtime: Instrumented.java](https://github.com/gradle/gradle/blob/5bdd5ce1e12bde6e1080bdbfbe7da3be158b0362/subprojects/core/src/main/java/org/gradle/internal/classpath/Instrumented.java#L226-L254)  
and [ProcessBuilder: Instrumented.java](https://github.com/gradle/gradle/blob/5bdd5ce1e12bde6e1080bdbfbe7da3be158b0362/subprojects/core/src/main/java/org/gradle/internal/classpath/Instrumented.java#L301)  
If that is the case then the defaults are those of [Runtime (Java Platform SE 7 )](https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#exec(java.lang.String%5B%5D,%20java.lang.String%5B%5D,%20java.io.File)) or [ProcessBuilder (Java Platform SE 7 )](https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#start()).

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

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [October 7, 2022, 9:49am UTC](https://discuss.gradle.org/t/devops-with-project-exec/43752/7 "2022-10-07T09:49:45Z")

</div>

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. 🙂
