关于在ruby中调用shell命令,大家想必知道使用:
然后可以通过 $? 来获取运行的状态,缺点就是无法获取运行失败后的错误信息。
哈,这样就可以捕获错误信息了
%x{'command'}
`command`
然后可以通过 $? 来获取运行的状态,缺点就是无法获取运行失败后的错误信息。
require "open3"
stdin, stdout, stderr = Open3.popen3('command')
stdin.puts('')
stdout.gets
stderr.gets
哈,这样就可以捕获错误信息了