Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a Ruby script that outputs a heap of text. As an example:

puts "line 1"
puts "line 2"
puts "line 3"
# etc... (obviously, this isn't how my script works..)

There's not a lot of data - perhaps about 8kb of character data in total.

When I run the script on the command line, it works as expected:

$ ./my-script.rb

line 1
line 2
line 3

But, when I push it into a file, the output is truncated at exactly 4096 bytes:

$ ./my-script.rb > output.txt

What would cause it to stop at 4kb?

Update: I just rewrote the script to output directly to a file, rather than print to the screen and capture the output, and the problem is still happening!

$output = File.new("file.txt")
$output << "line 1"  #etc..
share|improve this question
    
What's the output of ./my-script.rb | wc -c? –  Mladen Jablanović May 18 '10 at 7:58
    
@Mladen Jablanović: 8192 –  nickf May 18 '10 at 8:00

1 Answer 1

up vote 4 down vote accepted

Does your program terminates correctly? 4kB can be the OS internal buffer size for I/O, and the following data, present in the next buffer (up to 8kB which is the total size of your data) is lost when your program terminates abruptly or does not terminate at all.

share|improve this answer
2  
that's it! I had exit! in my code for testing... replaced with exit and it's fine... –  nickf May 18 '10 at 8:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.