Skip to content

Commit 606da15

Browse files
committed
Partially implement nqp::shell() on parrot (ignores it's third argument).
1 parent 001cf1d commit 606da15

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/vm/parrot/QAST/Operations.nqp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,6 +2379,7 @@ QAST::Operations.add_core_pirop_mapping('nfarunalt', 'nqp_nfa_run_alt', '0PsiPPP
23792379
# process related opcodes
23802380
QAST::Operations.add_core_pirop_mapping('exit', 'exit', '0i', :inlinable(1));
23812381
QAST::Operations.add_core_pirop_mapping('sleep', 'sleep', '0n', :inlinable(1));
2382+
QAST::Operations.add_core_pirop_mapping('shell', 'nqp_shell', 'IssP');
23822383
QAST::Operations.add_core_op('getenvhash', -> $qastcomp, $op {
23832384
if +@($op) != 0 {
23842385
nqp::die('getenvhash requires no operands');

src/vm/parrot/ops/nqp.ops

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,6 +3365,18 @@ inline op nqp_getlexrelcaller(out PMC, in PMC, in STR) :base_core {
33653365
$1 = result;
33663366
}
33673367

3368+
inline op nqp_shell(out INT, in STR, in STR, in PMC) {
3369+
STRING *command = $2;
3370+
STRING *dir = $3;
3371+
3372+
PMC *env = $4;
3373+
STRING * const old_cwd = Parrot_file_getcwd(interp);
3374+
Parrot_file_chdir(interp, dir);
3375+
$1 = Parrot_Run_OS_Command(interp, command);
3376+
Parrot_file_chdir(interp, old_cwd);
3377+
}
3378+
3379+
33683380
/*
33693381

33703382
=item nqp_encode

t/nqp/78-shell.t

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
plan(1);
2+
my $tmp_file := "tmp";
3+
nqp::shell("echo Hello > $tmp_file",nqp::cwd(),nqp::getenvhash());
4+
my $output := slurp($tmp_file);
5+
ok($output ~~ /^Hello/);

0 commit comments

Comments
 (0)