I'm porting something from linux to windows and I ran into a problem:

This works fine:

C:\TEMP> ruby -e "print %Q{foo\n}" > out.txt

But if I put it in a file...

----file test.rb----
print "foo\n"

--------------------

... then I get this strange behavior:

--------------------
C:\TEMP> test.rb
foo

C:\TEMP> ruby test.rb > out.txt

C:\TEMP> type out.txt
foo

C:\TEMP> test.rb > out.txt
C:\TEMP\test.rb:1:in `write': Bad file number (Errno::EBADF)
        from C:\TEMP\test.rb:1:in `print'
        from C:\TEMP\test.rb:1

--------------------

Why would 'test.rb' and 'ruby test.rb' behave differently? Something I
don't understand about DOS (very possible :) ?

If I remove the trailing '\n', then there is no error, but there is
another problem. An empty file gets written in the 'test.rb > out.txt'
case, but the other cases are fine.

What's going on?

Thanks!

--
Joel VanderWerf                          California PATH, UC Berkeley
mailto:vjoel / path.berkeley.edu                     Ph. (510) 231-9446
http://www.path.berkeley.edu                       FAX (510) 231-9512