Forum: Ruby %x and mswin32: missing output (from binary character)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jerome Zago (Guest)
on 2006-03-27 16:19
(Received via mailing list)
$ cat write.rb
puts "ab\032cd"

$ cat execute.rb
print %x{ruby write.rb}

$ ruby execute.rb
ab
[I expected "ab→cd"]

$ ruby --version   # I could reproduce with:
ruby 1.8.4 (2005-12-24) [i386-mswin32]
ruby 1.8.4 (2006-03-23) [i386-mswin32]
ruby 1.9.0 (2006-03-23) [i386-mswin32]

In comparison:

$ cat write.pl
print "ab\032cd\n"

$ cat execute.pl
print qx{perl write.pl};

$ perl execute.pl
ab→cd

$ perl --version
This is perl, v5.8.8 built for MSWin32-x86-multi-thread

-----

The following patch (against HEAD) solves this problem but might have
unwanted
side-effects:

--- io.c.orig	2006-03-01 11:06:03.000000000 +0100
+++ io.c	2006-03-24 19:22:19.885940500 +0100
@@ -4380,15 +4380,15 @@
 rb_f_backquote(VALUE obj, VALUE str)
 {
     volatile VALUE port;
     VALUE result;
     OpenFile *fptr;

     SafeStringValue(str);
-    port = pipe_open(1, &str, "r");
+    port = pipe_open(1, &str, "rb");
     if (NIL_P(port)) return rb_str_new(0,0);

     GetOpenFile(port, fptr);
     result = read_all(fptr, remain_size(fptr), Qnil);
     rb_io_close(port);

     return result;
This topic is locked and can not be replied to.