0

I have application minizinc in file ~/.bashrc, and I can call it on bash. I am building a Rails application that calls minizinc from bash, but I cannot do it. After executing this:

@cmd = ` bash -c "minizinc #{path} -n 1" `

I get the following error:

bash: minizinc: command not found

How can I change the Rails application user's PATH variable from the application? Or how do I tell the Rails application where this bash application is located?

2
  • are you running the rails application from the commandline? or from some IDE tool? Commented Oct 16, 2014 at 11:25
  • .bashrc is only sourced for interactive shells. You could try bash -ic "mini zinc #{path} -n 1", but there is probably a better solution. What exactly does "I have application minizinc in file ~/.bashrc` mean? Commented Oct 16, 2014 at 12:50

1 Answer 1

1

You have several options here. The one I think best suits your case and would recommend is using the command directly, instead of calling Bash to do the same as Ruby:

@cmd = `minizinc #{path} -n 1`

If you use it like this, the command is executed in a shell with an environment similar to the one where Ruby is running. Which means that the PATH variable will be the same. So if the dir containing the executable minizinc is in PATH when you start the Rails server, it should also be in the PATH variable of the shell running that command.

Now, if you really need to use Bash in the middle, I strike it as odd that the PATH variable is not the same as in Ruby (I tried it using IRB and seems to work as expected). You can check it by replacing your command with

bash -c "echo $PATH"

It should print the same value as

puts ENV['PATH']

when run in the Rails console.

If, after checking it, you see that the PATH variable of your Rails environment is incorrect, you can set it specifically for the Rails server:

PATH="<path_to_minizinc_dir>:$PATH" rails server

This sets the value of the PATH environment variable only for the command you are about to execute, in this case rails server.

Alternatively, you can surpass all this by simply using the absolute path to the executable:

@cmd = `bash -c "/full/path/to/minizinc #{path} -n 1"`

If you provide the full path to the command you want to execute, the PATH environment variable simply won't come into play, but I imagine this would be suboptimal for your case.

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.