我使用以下代码行调用方法send_csr1
中的方法send_crs
:
send_csr1(pipe.read,@username,@password)
问题是通常会执行下一行代码:
pipe.close_write
但不知何故,它不会导致cmd从未关闭。当我手动关闭它时,我得到错误:
in `read': Interrupt
from stack.rb:49:in `block in send_csr'
from stack.rb:45:in `popen'
from stack.rb:45:in `send_csr'
from stack.rb:88:in `block in <main>'
from stack.rb:87:in `each'
from stack.rb:87:in `<main>'
我的问题是我的代码需要更改什么,ruby surley关闭了cmd?
我的完整代码:
def send_csr
IO.popen('cmd', 'r+') do |pipe|
pipe.puts('cd C:/OpenSSL/bin')
pipe.puts('openssl.exe')
pipe.puts("req -config c:/OpenSSL/openssl.cnf -in #{@csr}")
send_csr1(pipe.read,@username,@password)
pipe.close_write
end
end
def send_csr1(text,user,password)
@conn.basic_auth(user,password)
@res = @conn.get do |request|
request.url "csr"
request.headers['Content-Type'] = 'text/plain'
request.body = "#{text}"
end
end