5050import java .io .IOException ;
5151import java .io .PrintStream ;
5252import java .math .BigInteger ;
53- import java .util .Arrays ;
54- import java .util .Collection ;
55- import java .util .List ;
56- import java .util .Map ;
53+ import java .util .*;
5754
5855@ CoreClass (name = "Kernel" )
5956public abstract class KernelNodes {
@@ -1949,7 +1946,7 @@ public RubyString sprintf(Object[] args) {
19491946 }
19501947 }
19511948
1952- @ CoreMethod (names = "system" , isModuleFunction = true , argumentsAsArray = true )
1949+ @ CoreMethod (names = "system" , isModuleFunction = true , needsSelf = false , required = 1 )
19531950 public abstract static class SystemNode extends CoreMethodNode {
19541951
19551952 public SystemNode (RubyContext context , SourceSection sourceSection ) {
@@ -1961,10 +1958,28 @@ public SystemNode(SystemNode prev) {
19611958 }
19621959
19631960 @ Specialization
1964- public Object fork ( Object [] args ) {
1961+ public boolean system ( RubyString command ) {
19651962 notDesignedForCompilation ();
1966- getContext ().getWarnings ().warn ("Kernel#system not implemented - defined to satisfy some metaprogramming in RubySpec" );
1967- return getContext ().getCoreLibrary ().getNilObject ();
1963+
1964+ // TOOD(CS 5-JAN-15): very simplistic implementation
1965+
1966+ final RubyHash env = getContext ().getCoreLibrary ().getENV ();
1967+
1968+ final List <String > envp = new ArrayList <>();
1969+
1970+ // TODO(CS): cast
1971+ for (KeyValue keyValue : HashOperations .verySlowToKeyValues (env )) {
1972+ envp .add (keyValue .getKey ().toString () + "=" + keyValue .getValue ().toString ());
1973+ }
1974+
1975+ // We need to run via bash to get the variable and other expansion we expect
1976+ try {
1977+ Runtime .getRuntime ().exec (new String []{"bash" , "-c" , command .toString ()}, envp .toArray (new String [envp .size ()]));
1978+ } catch (IOException e ) {
1979+ throw new RuntimeException (e );
1980+ }
1981+
1982+ return true ;
19681983 }
19691984
19701985 }
0 commit comments