Skip to content

Commit

Permalink
Start of implementation of run. Still needs work, but can execute com…
Browse files Browse the repository at this point in the history
…mands already.
  • Loading branch information
colomon committed Feb 26, 2012
1 parent a9d984a commit e5096c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/Builtins.cs
Expand Up @@ -1721,6 +1721,20 @@ public partial class Builtins {
return PosixWrapper.system(command);
}

public static int command_run(Variable argv, Variable env) {
Type Process = Type.GetType("GLib.Process,glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f");
Type SpawnFlags = Type.GetType("GLib.SpawnFlags,glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f");
MethodInfo spawn_sync = Process.GetMethod("SpawnSync");

object[] arguments = new object[]{ null, UnboxLoS(argv), UnboxLoS(env), Enum.ToObject(SpawnFlags, 0), null,
null, null, null };
bool result = (bool) spawn_sync.Invoke(null, arguments);
string stdout = (string) arguments[5];
string stderr = (string) arguments[6];
int exit_status = (int) arguments[7];
return result ? 1 : 0;
}

public static int path_chmod(string path, double mode) {
return PosixWrapper.chmod(path, (int) mode);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/CORE.setting
Expand Up @@ -3644,6 +3644,11 @@ sub shell($command) is unsafe {
Q:CgOp { (box Int (command_system (obj_getstr {$command}))) };
}
sub run(*@argv, :%env = %*ENV) is unsafe {
my @env = %env.map({ .key ~ "=" ~ .value });
Q:CgOp { (box Int (command_run {@argv} {@env})) };
}
multi sub open($filename, :$w?, :$a?, :$r?, :$rw?) is unsafe {
die "Not yet able to open both :r and :w" if ($r && $w) || $rw;
if $a {
Expand Down

0 comments on commit e5096c2

Please sign in to comment.