如果进程以参数开始,Ruby readline 会失败 [英] Ruby readline fails if process started with arguments
本文介绍了如果进程以参数开始,Ruby readline 会失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了最奇怪的问题.下面的代码工作正常:
I'm having the strangest issue. This code below works fine:
require 'json'
require 'net/http'
h = Net::HTTP.new("localhost", 4567)
while(l = gets.chomp!)
res = h.post("/api/v1/service/general",l)
puts res.body
end
但是,通过从参数中获取主机/端口的小修改:
However, with the small modification of getting host/port from parameters:
require 'json'
require 'net/http'
h = Net::HTTP.new(ARGV[0], ARGV[1])
while(l = gets.chomp!)
res = h.post("/api/v1/service/general",l)
puts res.body
end
..并以 ruby service.rb localhost 4567
开头 ...
..and starting with ruby service.rb localhost 4567
...
我收到此错误:
service.rb:4:in `gets': No such file or directory - localhost (Errno::ENOENT)
在 Ubuntu 11.04 上使用 ruby 1.9.2p0
Using ruby 1.9.2p0 on Ubuntu 11.04
推荐答案
你试过 while (l = $stdin.gets.chomp!)
吗?否则 Kernel#gets
从 ARGV
读取.
Have you tried while (l = $stdin.gets.chomp!)
? Otherwise Kernel#gets
reads from ARGV
.
这篇关于如果进程以参数开始,Ruby readline 会失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文