1

Grunt version: CLI - v1.2.0
local - v1.0.1

I'm using grunt-exec to start a local DynamoDB server. I'm doing this by creating a custom function in .bashrc then calling it inside grunt-exec. I also tried explicitly creating an alias, which didn't fix it.

~/.bashrc

runDynamo () {
    java -Djava.library.path=~/DynamoDBServer/DynamoDBLocal_lib -jar ~/DynamoDBServer/DynamoDBLocal.jar -sharedDb
}

Gruntfile.js

// ...
exec: {
    dynamo: {
        // Run DynamoDB locally at port 8000
        // This alias has been set during the inital installation
        command: "runDynamo"
    }
}
// ...
var mode = grunt.option("mode") || "test";
grunt.registerTask("run", ["exec:" + mode]);

When I run grunt run --mode=dynamo, I get the following error in stdout:

Running "exec:dynamo" (exec) task
>> /bin/sh: 1: runDynamo: not found
>> Exited with code: 127.
>> Error executing child process: Error: Process exited with code 127.

The command works fine when used directly in bash (i.e. $ runDynamo), so I'm not sure why grunt-exec isn't working here.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
spicypumpkin
  • 1,209
  • 2
  • 10
  • 21
  • 1
    IIRC, `~/.bashrc` is only sourced for interactive bash sessions (those either executed by `login` or run as `bash -i`. It's almost certain `grunt` will not be running `bash` in interactive mode (or might not even be using `bash` at all) when it forks a shell internally. [More info here](https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html). You can use `BASH_ENV` to set up a file for bash to source from there or wrap `grunt` in a script that will define that function for it. – mechalynx Apr 17 '17 at 08:46

0 Answers0