Giter Site home page Giter Site logo

Comments (6)

jharding avatar jharding commented on July 20, 2024

Can you provide me with an example so I can reproduce the issue?

from grunt-exec.

blakewest avatar blakewest commented on July 20, 2024

Hey, yeah sorry for that before. Here's an example. I made a test project, with a grunt file that looks like this.

module.exports = function(grunt){

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    exec: {
      testing: {
        command: 'source ./test_grunt_exec.sh',
      },
    }
  });

  grunt.loadNpmTasks('grunt-exec');
  grunt.registerTask('default', 'exec');
};

Then the test_grunt_exec.sh looks like this...

echo 'Working'

export TESTING="AlsoWorking"

Finally, here's sample shell output when testing this out:

Last login: Wed Dec 25 16:48:39 on ttys006
Macintosh-001ec21cda79:test bwest87$ printenv | grep TESTING
Macintosh-001ec21cda79:test bwest87$ grunt
Running "exec:testing" (exec) task
Working

Done, without errors.
Macintosh-001ec21cda79:test bwest87$ printenv | grep TESTING
Macintosh-001ec21cda79:test bwest87$ source ./test_grunt_exec.sh 
Working
Macintosh-001ec21cda79:test bwest87$ printenv | grep TESTING
TESTING=AlsoWorking
Macintosh-001ec21cda79:test bwest87$ 

As you can see... actually running the command from the terminal correctly sets the environment variables. But if I tried to do it only from the grunt task, the file runs, but the environment vars aren't set. The use case here is that I wanted certain variables set as part of the one start_up grunt task for a project I'm working on. I can tell people to separately run the bash command, but it would be cleaner to just tuck it in as part of grunt.

Any thoughts?

from grunt-exec.

yibuyisheng avatar yibuyisheng commented on July 20, 2024

A new child process will be produced when execute a shell command. So the environment variables you set are not in the main process but the child process which will be killed after executed.

from grunt-exec.

d48 avatar d48 commented on July 20, 2024

I have a similar use case in trying to set environment variables via bash script before more items are executed. source allows for any variables set to remain in the current context and available for any subprocesses spawned from that script. Having source support would be great

from grunt-exec.

kevinSuttle avatar kevinSuttle commented on July 20, 2024

I think this is an issue with Node in general, isn't it?

from grunt-exec.

gwicksted avatar gwicksted commented on July 20, 2024

Yes, this is not a grunt-exec issue nor a Grunt issue nor a NodeJS issue. It is a limitation of processes/subprocesses and env var handling.

Options:

  1. echo each environment variable (with delimiters) to stdout and parse them with the callback method.

  2. Or output a file that you can parse from within grunt.

  3. Define the env vars before calling grunt.

  4. Spawn a second grunt process immediately following your existing command (in the same grunt-exec call) and specify only the task(s) that require those env vars to be set. You can access them within grunt via process.env.ENV_VARIABLE or pass them into grunt as args via --argname=value and retrieving them via grunt.option('argname')

from grunt-exec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.