Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix so that current env will be propagated when starting a subshell.

git-svn-id: http://svn.codehaus.org/jruby/branches/enebo_block@2850 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
commit 60bd3eda70107a4f61bc397f3b3ffa70cf97ab08 1 parent 3ceefc4
Ola Bini olabini authored
Showing with 23 additions and 4 deletions.
  1. +16 −4 jruby/src/org/jruby/RubyKernel.java
  2. +7 −0 jruby/test/testEnv.rb
20 jruby/src/org/jruby/RubyKernel.java
View
@@ -48,6 +48,7 @@
import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
@@ -268,7 +269,7 @@ public static IRubyObject open(IRubyObject recv, IRubyObject[] args, Block block
// exec process, create IO with process
try {
// TODO: may need to part cli parms out ourself?
- Process p = Runtime.getRuntime().exec(command);
+ Process p = Runtime.getRuntime().exec(command,getCurrentEnv(recv.getRuntime()));
RubyIO io = new RubyIO(recv.getRuntime(), p);
if (block != null) {
@@ -956,6 +957,17 @@ public static int runInShell(IRuby runtime, IRubyObject[] rawArgs) {
return runInShell(runtime,rawArgs,runtime.getOutputStream());
}
+ private static String[] getCurrentEnv(IRuby runtime) {
+ Map h = ((RubyHash)runtime.getObject().getConstant("ENV")).getValueMap();
+ String[] ret = new String[h.size()];
+ int i=0;
+ for(Iterator iter = h.entrySet().iterator();iter.hasNext();i++) {
+ Map.Entry e = (Map.Entry)iter.next();
+ ret[i] = e.getKey().toString() + "=" + e.getValue().toString();
+ }
+ return ret;
+ }
+
public static int runInShell(IRuby runtime, IRubyObject[] rawArgs, OutputStream output) {
OutputStream error = runtime.getErrorStream();
InputStream input = runtime.getInputStream();
@@ -991,7 +1003,7 @@ public static int runInShell(IRuby runtime, IRubyObject[] rawArgs, OutputStream
argArray[0] = shell;
argArray[1] = shellSwitch;
argArray[2] = rawArgs[0].toString();
- aProcess = Runtime.getRuntime().exec(argArray, new String[]{}, pwd);
+ aProcess = Runtime.getRuntime().exec(argArray, getCurrentEnv(runtime), pwd);
} else {
// execute command directly, no wildcard expansion
if (rawArgs.length > 1) {
@@ -999,9 +1011,9 @@ public static int runInShell(IRuby runtime, IRubyObject[] rawArgs, OutputStream
for (int i=0;i<rawArgs.length;i++) {
argArray[i] = rawArgs[i].toString();
}
- aProcess = Runtime.getRuntime().exec(argArray, new String[]{}, pwd);
+ aProcess = Runtime.getRuntime().exec(argArray,getCurrentEnv(runtime), pwd);
} else {
- aProcess = Runtime.getRuntime().exec(rawArgs[0].toString(), new String[]{}, pwd);
+ aProcess = Runtime.getRuntime().exec(rawArgs[0].toString(), getCurrentEnv(runtime), pwd);
}
}
7 jruby/test/testEnv.rb
View
@@ -68,3 +68,10 @@
ENV['test'] = nil
test_equal(nil, ENV['test'])
+
+name = (RUBY_PLATFORM =~ /mswin/ ? '%__JRUBY_T1%' : '$__JRUBY_T1')
+v = `echo #{name}`
+test_equal "\n",v
+ENV['__JRUBY_T1'] = "abc"
+v = `echo #{name}`
+test_equal "abc\n",v
Please sign in to comment.
Something went wrong with that request. Please try again.