Apparently, synchronous output to stdout in JRuby is implemented differently from MRI. It appears to flush after each "print" whereas in MRI it does not. Can this behaviour be modified?

This sample code, demonstrates the lack of a flush after each print in MRI, even though $stdout.sync=true :

$ ruby -e "3.times {|i| print i+1; sleep 1}"

I see "123" printed all at once after a 3-second sleep, so clearly there was no flush after each print.

JRuby, too, has $sdtout.sync=true, but when I run the same sample code, there is a flush after each print, as I see each number printed, one at a time, with a one second sleep between.

The problem with flushing after each print is that in certain circumstances on the VMS operating system, this can cause the output of a separate record. Every time you flush to a VFC record file, a new record is created (See "1.8.2.2.1 Accessing Variable-Length or VFC Record Files in Record Mode" in http://h71000.www7.hp.com/doc/83final/5763/5763pro_006.html) which will cause problems for any program which expects to see the whole output in one record.

You might well wonder why anyone would use VFC, then. Unfortunately, this is one of those things that is beyond my control. If you execute some ruby code in a batch job, the output is logged to a VFC log file, and likewise if you redirect output from a command procedure, such as "@test.com/out=test.log".

Furthermore, the bug does not only afflict VFC files, but also interprocess communication of some kinds, e.g. we have discovered the same bug when a perl process opens a pipe to a ruby script and reads its output. Consider this:

$ perl -e 'open(COMMAND,"jruby -e \"3.times {|i| print i+1}\"|");while(<COMMAND>){print $_}'

The expected output is "123", and indeed on other platforms it is (Linux, for example).

Adjusting this example (quotes are different in DCL, the default shell on VMS) and running it on VMS:

$ perl -e "open(COMMAND,'jruby -e ""3.times {|i| print i+1}""|');while(<COMMAND>){print $_}"

The output is:

1
2
3

So the output of a new record each time a flush occurs on VMS is something that seems too difficult for me to work around. The only solution I can think of is to get rid of the "spurious" flushes that JRuby is executing but MRI is not. How can I do this?

Ben


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to