Skip to content

Commit

Permalink
Merge pull request #111 from perl6/child-env
Browse files Browse the repository at this point in the history
Pass %*ENV contents into ProcessBuilder in nqp::shell
Fixes 1 rakudo spectest in S02-magicals/env.t
  • Loading branch information
donaldh committed Aug 19, 2013
2 parents 9706494 + e8fb2cf commit 8733f0e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/GlobalContext.java
Expand Up @@ -194,6 +194,8 @@ public class GlobalContext {

ThreadLocal<WeakReference<ThreadContext>> currentThreadCtxRef;
WeakHashMap<Thread, ThreadContext> allThreads;

public SixModelObject processEnvironment = null;

/**
* Initializes the runtime environment.
Expand Down
19 changes: 18 additions & 1 deletion src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -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<String, String> 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();
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 8733f0e

Please sign in to comment.