From: David Masover Date: 2008-06-09T04:42:06+09:00 Subject: Re: How to redirect $stdin to read from a string? On Sunday 08 June 2008 14:13:54 A. Lester Buck III wrote: > require 'stringio' > > $stdin = StringIO.new "This is the test message" > > system("smbclient -M netbiosname") That only affects the stdin variable -- and if it did do what you're thinking, that's probably not a good idea anyway. You probably don't want to set stdout for the entire rest of your program. What you probably want is something like popen: def send_message message, netbiosname IO.popen "smbclient -M #{netbiosname}", 'w' do |io| message.each_line do |line| io.write line end end raise 'smbclient failed' unless $?.success? end I'm using each_line because it exists on both String and IO -- so you don't have to wrap the message in a StringIO. It won't work very well for large chunks of binary, but I don't think you'll be sending those...