Ruby读取文件后打印PS

Ruby读取文件后打印PS,ruby,file-io,printing,Ruby,File Io,Printing,我想知道我的输出发生了什么。当我运行这段代码时,它会正常工作,我传入我的文件名(ex15_sample.txt),然后它会打印出来。打印完文件后,它会打印出另外两个字符“PS”。知道这是为什么吗 我在Windows8 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?

我想知道我的输出发生了什么。当我运行这段代码时,它会正常工作,我传入我的文件名(ex15_sample.txt),然后它会打印出来。打印完文件后,它会打印出另外两个字符“PS”。知道这是为什么吗

我在Windows8 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

PS时,才会出现PowerShell提示符。每次执行命令后,它都会由PowerShell打印。这与Ruby完全无关。尝试运行
dir
,它也会打印PS。

方法不会在字符串末尾追加换行符。将
print txt.read
更改为
put txt.read
。您将在下一行看到
PS
powershell提示符,而不是在打印字符串的末尾。

是否从powershell提示符运行此命令?