0

I am executing commands in Ruby using system command, but I am facing the following problem:

I load an environment using the command Environment.bat, and I want to execute the second command which makes use of the environment that I have set up successfully in the previous command. However, it seems as if loading the environment earlier does not have any effect at all.

How to solve this problem so that the environment that I load in the ruby shell is used in the commands that I execute afterwards.

1
  • what does 'environment' look like? Is that a set of system variables or something? It might really help if you show some code Commented Apr 21, 2011 at 9:58

1 Answer 1

2

You might need to "chain" your two commands so that they get executed in the same system subshell. That is, if you're executing two commands in separate ruby "system" calls then they are modifying the environments of separate child programs which are not directly related.

system("env.bat") # Executes in child process 1.
system("program.exe") # Executes in child process 2.

In the above example, "program.exe" wouldn't know if "env.bat" had changed the environment by adding a new environment variable (for example) since they run in separate, unrelated processes.

system("env.bat && program.exe") # Both in the same child process.

But in this example the two commands are run in the same subshell process, one after the other, as long as "env.bat" doesn't exit with an error code. In this case "program.exe" would have access to any new environment variables set by "env.bat".

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.