From e8fb2cfe22c95bcde41637f45edc54127c17ae0f Mon Sep 17 00:00:00 2001 From: Donald Hunter Date: Sun, 18 Aug 2013 23:58:12 +0100 Subject: [PATCH] Pass %*ENV contents into ProcessBuilder in nqp::shell --- src/vm/jvm/QAST/Compiler.nqp | 2 +- .../org/perl6/nqp/runtime/GlobalContext.java | 2 ++ .../runtime/org/perl6/nqp/runtime/Ops.java | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/vm/jvm/QAST/Compiler.nqp b/src/vm/jvm/QAST/Compiler.nqp index 4a39c8ef3a..201232d268 100644 --- a/src/vm/jvm/QAST/Compiler.nqp +++ b/src/vm/jvm/QAST/Compiler.nqp @@ -1907,7 +1907,7 @@ QAST::OperationsJAST.map_classlib_core_op('mkdir', $TYPE_OPS, 'mkdir', [$RT_STR, QAST::OperationsJAST.map_classlib_core_op('rename', $TYPE_OPS, 'rename', [$RT_STR, $RT_STR], $RT_INT); QAST::OperationsJAST.map_classlib_core_op('copy', $TYPE_OPS, 'copy', [$RT_STR, $RT_STR], $RT_INT); QAST::OperationsJAST.map_classlib_core_op('link', $TYPE_OPS, 'link', [$RT_STR, $RT_STR], $RT_INT); -QAST::OperationsJAST.map_classlib_core_op('shell', $TYPE_OPS, 'shell', [$RT_STR], $RT_INT); +QAST::OperationsJAST.map_classlib_core_op('shell', $TYPE_OPS, 'shell', [$RT_STR], $RT_INT, :tc); QAST::OperationsJAST.map_classlib_core_op('symlink', $TYPE_OPS, 'symlink', [$RT_STR, $RT_STR], $RT_INT); QAST::OperationsJAST.map_classlib_core_op('opendir', $TYPE_OPS, 'opendir', [$RT_STR], $RT_OBJ, :tc); diff --git a/src/vm/jvm/runtime/org/perl6/nqp/runtime/GlobalContext.java b/src/vm/jvm/runtime/org/perl6/nqp/runtime/GlobalContext.java index b1ebd94f95..19267b571a 100644 --- a/src/vm/jvm/runtime/org/perl6/nqp/runtime/GlobalContext.java +++ b/src/vm/jvm/runtime/org/perl6/nqp/runtime/GlobalContext.java @@ -194,6 +194,8 @@ public class GlobalContext { ThreadLocal> currentThreadCtxRef; WeakHashMap allThreads; + + public SixModelObject processEnvironment = null; /** * Initializes the runtime environment. diff --git a/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java b/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java index fb92e36f40..bfd8025a49 100644 --- a/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java +++ b/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java @@ -661,13 +661,28 @@ public static long link(String before, String after) { return 0; } - public static long shell(String cmd) { + public static long shell(String cmd, ThreadContext tc) { long retval = 255; try { String os = System.getProperty("os.name").toLowerCase(); ProcessBuilder pb = os.indexOf("win") >= 0 ? new ProcessBuilder("cmd", "/c", cmd.replace('/', '\\')) : new ProcessBuilder("sh", "-c", cmd); + + Map pbEnv = pb.environment(); + SixModelObject processEnv = tc.gc.processEnvironment; + if (processEnv != null && processEnv.st.REPR instanceof VMHash) { + for (String key : ((VMHashInstance)processEnv).storage.keySet()) { + SixModelObject sixVal = processEnv.at_key_boxed(tc, key); + if (sixVal != null) { + String value = sixVal.get_str(tc); + if (value != null) { + pbEnv.put(key, value); + } + } + } + } + Process proc = pb.inheritIO().start(); proc.waitFor(); retval = proc.exitValue(); @@ -3811,6 +3826,8 @@ public static SixModelObject getenvhash(ThreadContext tc) { for (String envName : env.keySet()) res.bind_key_boxed(tc, envName, box_s(env.get(envName), strType, tc)); + tc.gc.processEnvironment = res; + return res; }