about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/dtas/process.rb9
-rw-r--r--test/test_process.rb12
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/dtas/process.rb b/lib/dtas/process.rb
index 2d7dcb0..3f1dc07 100644
--- a/lib/dtas/process.rb
+++ b/lib/dtas/process.rb
@@ -3,6 +3,7 @@
 # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
 require 'shellwords'
 require 'io/wait'
+require_relative '../dtas'
 module DTAS::Process # :nodoc:
   PIDS = {}
 
@@ -43,7 +44,11 @@ module DTAS::Process # :nodoc:
 
   # this is like backtick, but takes an array instead of a string
   # This will also raise on errors
-  def qx(cmd, opts = {})
+  def qx(env, cmd = {}, opts = {})
+    unless Hash === env
+      cmd, opts = env, cmd
+      env = {}
+    end
     r, w = IO.pipe
     opts = opts.merge(out: w)
     r.binmode
@@ -53,7 +58,7 @@ module DTAS::Process # :nodoc:
       opts[:err] = we
     end
     pid = begin
-      Process.spawn(*cmd, opts)
+      Process.spawn(env, *cmd, opts)
     rescue Errno::EINTR # Ruby bug?
       retry
     end
diff --git a/test/test_process.rb b/test/test_process.rb
new file mode 100644
index 0000000..a480312
--- /dev/null
+++ b/test/test_process.rb
@@ -0,0 +1,12 @@
+# -*- encoding: binary -*-
+# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net>
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+require './test/helper'
+require 'dtas/process'
+class TestProcess < Minitest::Unit::TestCase
+ include DTAS::Process
+
+ def test_qx_env
+   assert_equal "WORLD\n", qx({"HELLO" => "WORLD"}, 'echo $HELLO')
+ end
+end