我想知道我的輸出是怎麼回事。當我運行這段代碼時,它會正常工作,我傳入我的文件名(ex15_sample.txt),然後將它打印出來。打印完文件後,它會打印出兩個附加字符「PS」。任何想法,爲什麼這是?閱讀文件後紅寶石打印PS
我在Windows 8 64位機器上運行Ruby 2.0.0p576(x64)。
這裏是我的代碼:
# Prompts the user for input on the filename
print "What is the name of the file you would like printed? "
# Takes a command line argument and assigns it to the variable
filename = gets.chomp
# Declares another variable and initializes it by opening the file stored in the variable filename
txt = open(filename)
# Prints out a string with an interpolated string
puts "Here's your file #{filename}:"
# Prints out the file stored in the variable txt
print txt.read
# Closes the file
txt.close()
編輯:作爲一個方面說明,如果我打開文件,讀取和使用irb
我沒有得到多餘的字符打印。只有當我使用命令ruby ex15.rb
你是否在PowerShell提示符下運行這個? – ptierno 2014-11-05 20:42:05