Copying a IO stream results in corruption.
Posted
by StackedCrooked
on Stack Overflow
See other posts from Stack Overflow
or by StackedCrooked
Published on 2010-05-06T19:43:47Z
Indexed on
2010/05/06
19:48 UTC
Read the original article
Hit count: 203
ruby
I have a small Mongrel webserver that sends the stdout of a process to a http response:
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
This works well most of the time, but sometimes characters get duplicated. For example this is what I get from the "man ls" command:
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
For some mysterious reason capital letters get duplicated. Can anyone explain what's going on?
© Stack Overflow or respective owner