ホームページ  >  に質問  >  本文

ruby脚本gets方法没有接受输入

执行这个脚本的时候,kee=gets.chomp这行代码没有接受输入,请问是怎么回事?谢谢。

#!/usr/bin/ruby

require 'crypt/blowfish'

unless ARGV[0]
    puts "Usage: ruby encrypt.rb <filename.ext>"
    puts "Example: ruby encrypt.rb secret.stuff"
    exit
end

filename=ARGV[0].chomp
puts filename
c="Encrypted_#{filename}"
if File.exists?(c)
    puts "File already exists."
    exit
end
print "Enter your encryption key (1-56 bytes): "
kee=gets.chomp
begin
    blowfish=Crypt::Blowfish.new(kee)
    blowfish.encrypt_file(filename.to_str,c)
    puts 'Encryption sucess!'
rescue Exception => e
    puts "An error occurred during encryption: \n #{e}"
end
怪我咯怪我咯2710日前665

全員に返信(1)返信します

  • PHP中文网

    PHP中文网2017-04-24 09:11:27

    カーネルでgetsメソッドを呼び出しています。このgetメソッドは、AGRVが空でない限り、ARGVの内容を読み取ろうとし、その後STDINの内容を読み取ろうとします。

    http://www.ruby-doc.org/core-2.2.0/Kernel.html#method-i-gets

    呼び出す必要があるのは、STDIN.gets而不是getsなどのIO#getsです。

    http://www.ruby-doc.org/core-2.2.0/IO.html#method-i-gets

    返事
    0
  • キャンセル返事