当我运行这个简单的ruby脚本时:
a = `curl localhost`
puts "Result is: #{a}"
=> % Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed
=> 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to localhost port 80: Connection refused
=> Result is:
看到运行命令时打印结果,变量为空。但是,如果我以相同的格式运行任何其他命令,它就像我期望的那样工作:
a = `ls`
puts "Result is: #{a}"
=> Result is: test.rb
如何将第一个curl命令的结果存储到变量中?