执行这个脚本的时候,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
Anda sedang memanggil kaedah gets dalam Kernel Kaedah gets ini akan cuba membaca kandungan ARGV, melainkan AGRV kosong, maka ia akan cuba membaca kandungan STDIN.
Anda harus memanggil IO#gets, seperti
STDIN.gets
dan bukannyagets
.