Is there an explanation for the following behaviour:
ruby -e “puts ‘abcd’” > aaa
file aaa will contain ‘abcd’
However if you run
ruby -e “puts ‘abcd’;exit!” > aaa
file aaa will be empty.
At the same time:
ruby -e "puts ‘abcd’;exit!"
will display ‘abcd’ on the screen.
Somehow, exit! do not only execute at_exit handler and bypasses finalizers, but also do not flush the last puts if stdout is redirected. Very strange.
[x86.bison:9]gfb> ruby -v
ruby 1.6.8 (2002-12-24) [i386-solaris2.8]
Thank you,
Gennady.
P.S. Same behaviour on Linux
[lnx.bear:54]bystr> ruby -v
ruby 1.6.8 (2002-12-24) [i686-linux]
In Message-Id: 000a01c33d05$933e4b90$c20ca8c0@gfb
“Gennady” gfb@tonesoft.com writes:
Somehow, exit! do not only execute at_exit handler and bypasses
finalizers, but also do not flush the last puts if stdout is
redirected. Very strange.
Not so since exit! calls _exit() in C level, which is expected to
behave such way. Namely exit! is prepared for a occasion to exit as
soon as possible, without extra cleaning up.
Note stdio associated with a terminal is set to a line oriented
buffering mode and puts outputs a line.
> ruby -v
ruby 1.7.2 (2002-05-07) [i386-freebsd]
> ruby -e 'puts "abcd"; exit!'
abcd
> ruby -e 'print "abcd"; exit!'
> ruby -e 'print "abcd\n"; exit!'
abcd
That’s all. Tty flushes a buffer when it sees a `\n’.
tty(4), termios(4) ?
···
–
kjana@dm4lab.to June 28, 2003
It is comparison that makes men happy or miserable.