%x []捕获所有输出吗?

时间:2011-03-24 04:36:22

标签: ruby

如果我运行此代码:

svn_output = %x[svn update /Users/radek/Sites/db2.rft -r 11105 --force ]
puts
puts " output is  =#{svn_output}="

我得到了这个结果

svn: Working copy '/Users/radek/Sites/db2.rft' locked
svn: run 'svn cleanup' to remove locks (type 'svn help cleanup' for details)

 output is  ==

但是我希望变量svn_output中的svn出现错误消息。这可能吗?

1 个答案:

答案 0 :(得分:12)

您想将stderr重定向到stdout:

svn_output = %x[svn update /Users/radek/Sites/db2.rft -r 11105 --force 2>&1]
puts
puts " output is  =#{svn_output}="