Git Product home page Git Product logo

Comments (7)

mitchellh avatar mitchellh commented on July 18, 2024

Note at the moment I'm using this little helper method to work around this:

    # This method changes the environmental variables of the process to
    # that of this environment, yields, and then resets them. This allows
    # us to change the environment temporarily.
    def with_env_changes
      stashed = {}

      begin
        @env.each do |key, value|
          stashed[key] = ENV[key]
          ENV[key] = value
        end

        yield
      ensure
        stashed.each do |key, value|
          ENV[key] = stashed[key]
        end
      end
    end

Then using it like so:

process = ChildProcess.build("blah", "blah")
with_env_changes do
  process.start
end

And this gets around the issue since all platforms I believe inherit environmental variables. However, it seems hacky and isn't threadsafe and pushes a lot of that logic down to the client, whereas environmental variables are a first class argument in any exec type API, so I think it should be in ChildProcess as well. :)

from childprocess.

jarib avatar jarib commented on July 18, 2024

I agree. I'll see what I can do.

from childprocess.

jarib avatar jarib commented on July 18, 2024

Does that look ok to you?

Right now the child process will inherit the parent's environment when you call #start, which I think makes sense. One could argue that we should store a copy of the parent environment when ChildProces.build is called instead. Thoughts?

from childprocess.

mitchellh avatar mitchellh commented on July 18, 2024

Looks very good! I see you properly got the edge-cases that Java and Windows have of SETTING the environment instead of setting overrides for the current environment, which is the only thing I knew to look for in this change.

As for when to set the environment, I think start is the right place. All "fork-like" APIs do the actual environment copy on fork, so I think doing it on "start" for childprocess makes sense.

Thank you!

When will there be a gem push? :)

from childprocess.

jarib avatar jarib commented on July 18, 2024

Pushed!

from childprocess.

mitchellh avatar mitchellh commented on July 18, 2024

Thank you for the quick turnaround on this. Be proud you have the best subprocess library for Ruby hands down.

from childprocess.

jarib avatar jarib commented on July 18, 2024

Thanks :)

from childprocess.

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.