2

I am using command:

./cpp-generator > ~/log.log

But when I open the log.log the file is shortened. It ends in the middle of a word. But if I run just:

./cpp-generator 

in terminal, the result is whole, full output.

  • 1
    Is there a mention of /dev/fd or /dev/std* or /proc/self/fd in cpp-generator. Is the file also truncated if you use ./cpp-generator | cat > ~/log.log or ./cpp-generator >> ~/log.log? – Stéphane Chazelas Aug 4 '15 at 9:20
  • @StéphaneChazelas In both cases it return truncated output. I cpp-generator I use only printf and cout for output... and I search for /dev/fd (/dev/std and /proc/self/fd) and did not find anything with it... – Dusan Plavak Aug 4 '15 at 9:37
  • 1
    Is it possible that cpp-generator or any of the log-generating process it spawns be killed or call abort(), or _exit() without getting a chance to flush its stdio buffers? (when the output goes to a terminal, the buffering is line-based instead of block-based which would explain the difference) – Stéphane Chazelas Aug 4 '15 at 9:54
  • it is not. cpp-generator is basically client (github.com/mostphotos/beanstalkpp) connecting to the server but it is one process. – Dusan Plavak Aug 4 '15 at 10:42
  • Is it truncating if you run it as stdbuf -o0 cpp-generator > log.log – Stéphane Chazelas Aug 4 '15 at 10:50
1

Ok, so as @StéphaneChazelas said the possible cause is that ./cpp-generator is killed Terminal has line-based buffering instead of block buffering in ./cpp-generator so this is why the terminal will print the all output.

I gave ./cpp-generator enough time to print the message, but because it run in loop I always end it with ctrl + c - therefore I killed it and block-based buffers does not have a chance to write out to the file...

working solution is run ./cpp-generator like this:

stdbuf -o0 cpp-generator > log.log

Thanks @StéphaneChazelas

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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