Run a command line with custom environment
Open.popen3
optionally accepts a hash as the first argument (in which case your command would be the second argument:
cmd = 'a_prog --arg ... --arg2 ...'
Open3.popen3({"MYVAR" => "a_value"}, "#{cmd}") { |i,o,e|
output = o.read()
error = e.read()
# FIXME: don't want to *separate out* stderr like this
repr = "$ #{cmd}\n#{output}"
}
Open
uses Process.spawn
to start the command, so you can look at the documentation for Process.spawn to see all of it's options.
Running a command with specific environment settings - one-liner
set foo=bar&.\foo.py&set foo=
It should be noted that batch files are parsed one line at the time, so one liners like this are problematic there (setlocal ENABLEDELAYEDEXPANSION can help out in those cases)
Setting an environment variable before a command in Bash is not working for the second command in a pipe
FOO=bar bash -c 'somecommand someargs | somecommand2'
Related Topics
How to Run Rake with --Trace Within Capistrano
You Don't Have Write Permissions into the /Var/Lib/Gems/1.9.1 Directory
Ruby Incorrectly Parses 2 Digit Year
How to Extend Redcarpet to Support Auto Linking User Mentions
Validates_Inclusion_Of No Longer Working the Same in Rails 4.1
Creating a Test Suite Using Ruby Minitest
Converting an Array of Hashes to One Hash in Ruby
Rails: How to to Download a File from a Http and Save It into Database
How to Programmatically Check If a Certificate Has Been Revoked
Ruby Variable as Same Object (Pointers)
Serialize Ruby Object to JSON and Back
How to Create a Charge and a Customer in Stripe (Rails)
Updated to Osx 10.9, Now Getting Ruby Error Using Homebrew