# Exec task succeeding when executed directly but failing when executed via parent project

**URL:** <https://discuss.gradle.org/t/exec-task-succeeding-when-executed-directly-but-failing-when-executed-via-parent-project/28346>\
**Category:** Help/Discuss\
**Created:** [August 25, 2018, 4:32pm UTC](https://discuss.gradle.org/t/exec-task-succeeding-when-executed-directly-but-failing-when-executed-via-parent-project/28346 "2018-08-25T16:32:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanodeath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nanodeath/32/5423_2.png) [@nanodeath](https://discuss.gradle.org/u/nanodeath)\
**Post date:** [August 25, 2018, 4:32pm UTC](https://discuss.gradle.org/t/exec-task-succeeding-when-executed-directly-but-failing-when-executed-via-parent-project/28346/1 "2018-08-25T16:32:30Z")

</div>

Hi,

I have the following task, which exists in a subproject:

```gradle
def suffix = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
task cssBuild(type: Exec) {
    def input = 'src/main/sass'
    def output = 'build/web'
    inputs.dir(input)
    outputs.dir(output)
    commandLine "node_modules/.bin/node-sass$suffix", input, '--recursive', '--output', output
}

```

If I invoke the `gradlew clean cssBuild --info` from within this subproject, I get

```gradle
Starting process 'command 'node_modules/.bin/node-sass.cmd''. Working directory: [project]\[subproject] Command: node_modules/.bin/node-sass.cmd src/main/sass --recursive --output build/web
Successfully started process 'command 'node_modules/.bin/node-sass.cmd''
Rendering Complete, saving .css file...
Wrote CSS to [project]\[subproject]\build\web\main.css
Wrote 1 CSS files to [project]\[subproject]\build\web
:cssBuild (Thread[Task worker for ':',5,main]) completed. Took 0.957 secs.

```

But if, from the parent project, I run `gradlew assemble --stacktrace` (which hits the above task), I get:

```gradle
> Task :[subproject]:cssBuild FAILED

FAILURE: Build failed with an exception.
// snip
Caused by: java.io.IOException: Cannot run program "node_modules/.bin/node-sass.cmd" (in directory "[project]\[subproject]"): CreateProcess error=2, The system cannot find the file specified
        at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
        ... 7 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
        ... 8 more

```

Even though the file definitely exists.

Basically, in both cases, the working directory is shown to be the same, and the program is shown to be the same. So why is it failing in one but not the other?

Gradle 4.9, Windows.

---

<div class="post-metadata">

**Author:** ![nanodeath](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nanodeath/32/5423_2.png) [@nanodeath](https://discuss.gradle.org/u/nanodeath)\
**Post date:** [August 25, 2018, 4:54pm UTC](https://discuss.gradle.org/t/exec-task-succeeding-when-executed-directly-but-failing-when-executed-via-parent-project/28346/2 "2018-08-25T16:54:32Z")

</div>

I figured out a workaround. If I update the `commandLine` bit to this, it works:

```gradle
commandLine "${projectDir}/node_modules/.bin/node-sass$suffix", input, '--recursive', '--output', output

```

(Adding `${projectDir}`). But why is this necessary? Does `commandLine` really not factor in the working directory?

---

<div class="post-metadata">

**Author:** ![nicolas06](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nicolas06/32/7230_2.png) [@nicolas06](https://discuss.gradle.org/u/nicolas06)\
**Post date:** [September 23, 2018, 10:54am UTC](https://discuss.gradle.org/t/exec-task-succeeding-when-executed-directly-but-failing-when-executed-via-parent-project/28346/3 "2018-09-23T10:54:09Z")

</div>

Hi Max,

I had the same issue and figured out the same workaround. I don’t know why but `commandLine` does not factor in the working directory.
