ruby脚本gets方法没有接受输入
怪我咯
怪我咯 2017-04-24 09:09:27
0
1
658

执行这个脚本的时候,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
怪我咯
怪我咯

走同样的路,发现不同的人生

모든 응답(1)
洪涛

커널에서 gets 메소드를 호출하고 있습니다. 이 gets 메소드는 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

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!