From the Ruby docs, it seems you can't, but you can do it:
spawn("ls", 0 => ["/tmp/ruby_stdout_temp", "w"])
stdoutStr=File.read("/tmp/ruby_stdout_temp")
You can also do the same with a standard error. Or, if you do not and do not mind popen:
io=IO.popen("ls")
stdout=io.read
source
share