Revision
1062
Author
lsansonetti@apple.com
Date
2009-03-22 13:37:41 -0700 (Sun, 22 Mar 2009)

Log Message

re-implemented backquotes

Modified Paths

Diff

Modified: MacRuby/branches/experimental/io.c (1061 => 1062)


--- MacRuby/branches/experimental/io.c	2009-03-22 19:39:00 UTC (rev 1061)
+++ MacRuby/branches/experimental/io.c	2009-03-22 20:37:41 UTC (rev 1062)
@@ -367,6 +367,12 @@
     if (close_write && io_struct->writeStream != NULL) {
 	CFWriteStreamClose(io_struct->writeStream);
     }
+    if (io_struct->fp != NULL) {
+	const int status = pclose(io_struct->fp);
+	io_struct->fp = NULL;
+	// TODO find out the real pid instead of passing -1
+	rb_last_status_set(status, -1);
+    }
 }
 
 int
@@ -1548,7 +1554,6 @@
 io_close(VALUE io, bool close_read, bool close_write)
 {
     rb_io_t *io_struct = ExtractIOStruct(io);
-
     io_struct_close(io_struct, close_read, close_write);
 }
 
@@ -2903,7 +2908,12 @@
 static VALUE
 rb_f_backquote(VALUE obj, SEL sel, VALUE str)
 {
-rb_notimplement();
+    VALUE io = rb_io_s_popen(rb_cIO, 0, 1, &str);
+    VALUE bstr = rb_bytestring_new();
+    rb_io_read_all(ExtractIOStruct(io), bstr);
+    rb_io_close(io, 0);
+
+    return bstr;
 }