Closed kbrock closed 9 years ago
:+1:
Can you update documentation as well? (You can do it in a separate commit with [skip ci] to avoid rekicking travis).
@Fryguy great question
answer: {}
acts the same as not passing the parameter
#!/usr/bin/env ruby
require "open3"
command = "echo ${ABC}"
output, error, status = Open3.capture3(command)
puts "1 output no env: #{output}"
output, error, status = Open3.capture3({}, command)
puts "2 output {} env: #{output}"
output, error, status = Open3.capture3({'ABC' => 'custom'}, command)
puts "3 output var env: #{output}"
$ ABC=123 ./test_spawn.rb
ABC=123
---
1 output no env: 123
2 output {} env: 123
3 output var env: custom
@Fryguy followup on env variables
ENV["CDE"]="cde"
AwesomeSpawn.run('echo "${ABC} ${CDE}"', :env => {"ABC" => "abcde"}).output
# => "abcde cde\n"
AwesomeSpawn.run('echo "${ABC} ${CDE}"', :env => {"ABC" => "abcde"}, :unsetenv_others=>true).output
# => "abcde \n"
When we detach a process, we tend to pass a set of environment variable.
This adds the
:env
option toAwesomeSpawn#run
so users can specify both the env and argv for a spawned task.