Skip to content

Commit e8fb2cf

Browse files
committed
Pass %*ENV contents into ProcessBuilder in nqp::shell
1 parent 9706494 commit e8fb2cf

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,7 @@ QAST::OperationsJAST.map_classlib_core_op('mkdir', $TYPE_OPS, 'mkdir', [$RT_STR,
19071907
QAST::OperationsJAST.map_classlib_core_op('rename', $TYPE_OPS, 'rename', [$RT_STR, $RT_STR], $RT_INT);
19081908
QAST::OperationsJAST.map_classlib_core_op('copy', $TYPE_OPS, 'copy', [$RT_STR, $RT_STR], $RT_INT);
19091909
QAST::OperationsJAST.map_classlib_core_op('link', $TYPE_OPS, 'link', [$RT_STR, $RT_STR], $RT_INT);
1910-
QAST::OperationsJAST.map_classlib_core_op('shell', $TYPE_OPS, 'shell', [$RT_STR], $RT_INT);
1910+
QAST::OperationsJAST.map_classlib_core_op('shell', $TYPE_OPS, 'shell', [$RT_STR], $RT_INT, :tc);
19111911
QAST::OperationsJAST.map_classlib_core_op('symlink', $TYPE_OPS, 'symlink', [$RT_STR, $RT_STR], $RT_INT);
19121912

19131913
QAST::OperationsJAST.map_classlib_core_op('opendir', $TYPE_OPS, 'opendir', [$RT_STR], $RT_OBJ, :tc);

src/vm/jvm/runtime/org/perl6/nqp/runtime/GlobalContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ public class GlobalContext {
194194

195195
ThreadLocal<WeakReference<ThreadContext>> currentThreadCtxRef;
196196
WeakHashMap<Thread, ThreadContext> allThreads;
197+
198+
public SixModelObject processEnvironment = null;
197199

198200
/**
199201
* Initializes the runtime environment.

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,13 +661,28 @@ public static long link(String before, String after) {
661661
return 0;
662662
}
663663

664-
public static long shell(String cmd) {
664+
public static long shell(String cmd, ThreadContext tc) {
665665
long retval = 255;
666666
try {
667667
String os = System.getProperty("os.name").toLowerCase();
668668
ProcessBuilder pb = os.indexOf("win") >= 0
669669
? new ProcessBuilder("cmd", "/c", cmd.replace('/', '\\'))
670670
: new ProcessBuilder("sh", "-c", cmd);
671+
672+
Map<String, String> pbEnv = pb.environment();
673+
SixModelObject processEnv = tc.gc.processEnvironment;
674+
if (processEnv != null && processEnv.st.REPR instanceof VMHash) {
675+
for (String key : ((VMHashInstance)processEnv).storage.keySet()) {
676+
SixModelObject sixVal = processEnv.at_key_boxed(tc, key);
677+
if (sixVal != null) {
678+
String value = sixVal.get_str(tc);
679+
if (value != null) {
680+
pbEnv.put(key, value);
681+
}
682+
}
683+
}
684+
}
685+
671686
Process proc = pb.inheritIO().start();
672687
proc.waitFor();
673688
retval = proc.exitValue();
@@ -3811,6 +3826,8 @@ public static SixModelObject getenvhash(ThreadContext tc) {
38113826
for (String envName : env.keySet())
38123827
res.bind_key_boxed(tc, envName, box_s(env.get(envName), strType, tc));
38133828

3829+
tc.gc.processEnvironment = res;
3830+
38143831
return res;
38153832
}
38163833

0 commit comments

Comments
 (0)