0

I am creating the following method which sets my environment variables:

  def set_time
    puts "setting_time"
    system("export GIT_COMMITTER_DATE='#{@date}'")
    system("export GIT_AUTHOR_DATE='#{@date}'")
  end

But for some reason when I go into my console after running this, the environment variables have not been added! I am able to run other command line interface keywords and it works. How can I set environment variables from Ruby?

1 Answer 1

1

The reason they don't 'stick' is because when you run a shell command from Ruby it opens a new process. And that process, as a child to your current Ruby process is not persistent, as eventually it dies.

A good resource on this is Jesse Storimer's blog post, with much more information about environment and processes than I will type here.

Depending on your operating system, you can use Ruby to write to your 'rc' files, such as ~/.bashrc or on Windows change your registry, if you really want to have these be persistent over logins.

So the answer is, you ARE setting and exporting environment variables. They simply aren't surviving past the life of the child process.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.