I have the following task in my *build.gradle* file:

```
task init_dev {
    doLast {
        exec {
            workingDir '.'
            commandLine 'mongo', '--port', '27018', '<', 'init/mongodb-init-dev'
        }
    }
}

```

when I execute it, I get the following

```
14:52:49: Executing task 'init_dev --info'...

The client will now receive all logging from the daemon (pid: 3919). The daemon log file: /Users/jscherman/.gradle/daemon/4.8.1/daemon-3919.out.log
Starting 42nd build in daemon [uptime: 49 mins 28.148 secs, performance: 99%, no major garbage collections]
Using 8 worker leases.
Starting Build
Settings evaluated using settings file '/Users/jscherman/IdeaProjects/demo/settings.gradle'.
Projects loaded. Root project using build file '/Users/jscherman/IdeaProjects/demo/build.gradle'.
Included projects: [root project 'demo', project ':mock-metrics-generator', project ':demo-be']

> Configure project :
Evaluating root project 'demo' using build file '/Users/jscherman/IdeaProjects/demo/build.gradle'.
Applying dependency management to configuration 'annotationProcessor' in project 'mock-metrics-generator'
Applying dependency management to configuration 'apiElements' in project 'mock-metrics-generator'
Applying dependency management to configuration 'archives' in project 'mock-metrics-generator'
Applying dependency management to configuration 'bootArchives' in project 'mock-metrics-generator'
Applying dependency management to configuration 'compile' in project 'mock-metrics-generator'
Applying dependency management to configuration 'compileClasspath' in project 'mock-metrics-generator'
Applying dependency management to configuration 'compileOnly' in project 'mock-metrics-generator'
Applying dependency management to configuration 'default' in project 'mock-metrics-generator'
Applying dependency management to configuration 'implementation' in project 'mock-metrics-generator'
Applying dependency management to configuration 'runtime' in project 'mock-metrics-generator'
Applying dependency management to configuration 'runtimeClasspath' in project 'mock-metrics-generator'
Applying dependency management to configuration 'runtimeElements' in project 'mock-metrics-generator'
Applying dependency management to configuration 'runtimeOnly' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testAnnotationProcessor' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testCompile' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testCompileClasspath' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testCompileOnly' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testImplementation' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testRuntime' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testRuntimeClasspath' in project 'mock-metrics-generator'
Applying dependency management to configuration 'testRuntimeOnly' in project 'mock-metrics-generator'
Applying dependency management to configuration 'annotationProcessor' in project 'demo-be'
Applying dependency management to configuration 'apiElements' in project 'demo-be'
Applying dependency management to configuration 'archives' in project 'demo-be'
Applying dependency management to configuration 'bootArchives' in project 'demo-be'
Applying dependency management to configuration 'compile' in project 'demo-be'
Applying dependency management to configuration 'compileClasspath' in project 'demo-be'
Applying dependency management to configuration 'compileOnly' in project 'demo-be'
Applying dependency management to configuration 'default' in project 'demo-be'
Applying dependency management to configuration 'implementation' in project 'demo-be'
Applying dependency management to configuration 'runtime' in project 'demo-be'
Applying dependency management to configuration 'runtimeClasspath' in project 'demo-be'
Applying dependency management to configuration 'runtimeElements' in project 'demo-be'
Applying dependency management to configuration 'runtimeOnly' in project 'demo-be'
Applying dependency management to configuration 'testAnnotationProcessor' in project 'demo-be'
Applying dependency management to configuration 'testCompile' in project 'demo-be'
Applying dependency management to configuration 'testCompileClasspath' in project 'demo-be'
Applying dependency management to configuration 'testCompileOnly' in project 'demo-be'
Applying dependency management to configuration 'testImplementation' in project 'demo-be'
Applying dependency management to configuration 'testRuntime' in project 'demo-be'
Applying dependency management to configuration 'testRuntimeClasspath' in project 'demo-be'
Applying dependency management to configuration 'testRuntimeOnly' in project 'demo-be'

> Configure project :mock-metrics-generator
Evaluating project ':mock-metrics-generator' using build file '/Users/jscherman/IdeaProjects/demo/mock-metrics-generator/build.gradle'.

> Configure project :demo-be
Evaluating project ':demo-be' using build file '/Users/jscherman/IdeaProjects/demo/demo-be/build.gradle'.
All projects evaluated.
Selected primary task 'init_dev' from project :
Tasks to be executed: [task ':init_dev']
:init_dev (Thread[Task worker for ':',5,main]) started.

> Task :init_dev FAILED
Task ':init_dev' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
Starting process 'command 'mongo''. Working directory: /Users/jscherman/IdeaProjects/demo Command: mongo --port 27018 < init/mongodb-init-dev
Successfully started process 'command 'mongo''
MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27018/%3C
Implicit session: session { "id" : UUID("0b3d098a-00e3-4802-bf9f-af7d1f7a6629") }
MongoDB server version: 4.0.3
2019-01-23T14:52:49.741-0300 E QUERY    [js] SyntaxError: missing ; before statement @init/mongodb-init-dev:1:4
failed to load: init/mongodb-init-dev
:init_dev (Thread[Task worker for ':',5,main]) completed. Took 0.217 secs.

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/jscherman/IdeaProjects/demo/build.gradle' line: 60

* What went wrong:
Execution failed for task ':init_dev'.
> Process 'command 'mongo'' finished with non-zero exit value 253

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
1 actionable task: 1 executed
Process 'command 'mongo'' finished with non-zero exit value 253
Open File
14:52:49: Task execution finished 'init_dev --info'.

```

---

*mongodb-init-dev*

```
use my_db

db.nodes.drop()

db.nodes.insertMany([
    {
        "_id":"node-1",
        "classifier":{
            "lowerThreshold":3000,
            "upperThreshold":5000,
            "timeUnit":"MILLISECONDS"
        }
    },
    {
        "_id":"node-2",
        "classifier":{
            "lowerThreshold":2,
            "upperThreshold":4,
            "timeUnit":"SECONDS"
        }
    },
    {
        "_id":"node-3",
        "classifier":{
            "lowerThreshold":3000,
            "upperThreshold":5000,
            "timeUnit":"MILLISECONDS"
        }
    },
    {
        "_id":"node-4",
        "classifier":{
            "lowerThreshold":1200,
            "upperThreshold":4000,
            "timeUnit":"MILLISECONDS"
        }
    },
    {
        "_id":"node-5",
        "classifier":{
            "lowerThreshold":2000,
            "upperThreshold":5000,
            "timeUnit":"MILLISECONDS"
        }
    }])

```

Now, when I run that command manually, it works

```
madmin’s-MacBook-Pro:demo jscherman$ pwd
/Users/jscherman/IdeaProjects/demo
madmin’s-MacBook-Pro:demo jscherman$ mongo --port 27018 < init/mongodb-init-dev
MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27018/
Implicit session: session { "id" : UUID("31e9f04c-4a7b-474d-ac18-93f0fb725c86") }
MongoDB server version: 4.0.3
switched to db demo_db
true
{
    "acknowledged" : true,
    "insertedIds" : [
        "node-1",
        "node-2",
        "node-3",
        "node-4",
        "node-5"
    ]
}
bye

```

Any idea why this is happening? Thanks in advance.