Ruby 复制IO流会导致损坏

Ruby 复制IO流会导致损坏,ruby,Ruby,我有一个小型的Mongrel Web服务器,它将进程的标准输出发送到http响应: response.start(200) do |head,out| head["Content-Type"] = "text/html" status = POpen4::popen4(command) do |stdout, stderr, stdin, pid| stdin.close() FileUtils.copy_stream(stdout, out) FileUtils

我有一个小型的Mongrel Web服务器,它将进程的标准输出发送到http响应:

response.start(200) do |head,out|
  head["Content-Type"] = "text/html"
  status = POpen4::popen4(command) do |stdout, stderr, stdin, pid|
    stdin.close()
    FileUtils.copy_stream(stdout, out)
    FileUtils.copy_stream(stderr, out)
    puts "Sent response."
  end
end
这在大多数情况下都很有效,但有时角色会被复制。例如,这是我从“man ls”命令中得到的:


由于某种神秘的原因,大写字母被复制了。有人能解释发生了什么吗?

这是
man
的实际输出。在控制台中显示时,您看到的重复字符(以及其他一些您没有看到的字符,如退格字符)用于格式化输出,如下划线文本等

为了过滤掉这些格式字符,请查看Linux手册页中的HOWTO

顺便说一句,我不确定
text/html
是否适合这种输出

LS(1)                            User Commands                           LS(1)



NNAAMMEE
       ls - list directory contents

SSYYNNOOPPSSIISS
       llss [_O_P_T_I_O_N]... [_F_I_L_E]...

DDEESSCCRRIIPPTTIIOONN
       List  information  about  the FILEs (the current directory by default).
       Sort entries alphabetically if none of --ccffttuuvvSSUUXX nor ----ssoorrtt.

       Mandatory arguments to long options are  mandatory  for  short  options