views:

49

answers:

1

I'm using /usr/bin/file -i SOME_FILE to detect whether it contains non-ascii-and-utf characters. However, it produces different result when the application is deployed to apache+passenger.

In 'script/console', above line gives: SOME_FILE: text/plain; charset=utf-8

In passenger, it gives:

SOME_FILE: regular file

Since I am pointing to absolute path of 'file', this is strange. I'm guessing the library used by it is different in Passenger. Any comments?

If this is not the right way to detect a text file's encoding, what is the best approach(in ruby)?

Thank you very much.

A: 

I'm guessing this is a difference between versions of the 'file' utility between your development machine and the server. Have you tried running them from a terminal of both machines?

Manfred Stienstra
Thank you. I'm running both from my dev machine, and I have used '/usr/bin/file' so they should have been running the same utility.
Guoliang Cao
I am able to reproduce this problem differently now. I have 2 ruby installation: MAC bundled Ruby 1.8.6 and Ruby 1.8.7 installed by RVM(Ruby Version Manager). When I invoke irb of 1.8.6, I get SOME_FILE: regular file. When I invoke irb of 1.8.7, I get SOME_FILE: text/plain; charset=utf-8. I believe this has something to do with how Ruby is compiled and installed.
Guoliang Cao
Further note: When I run irb as myself, that command outputs SOME_FILE: text/plain; charset=utf-8. When I run as root, it outputs SOME_FILE: regular file. I think it is because those 2 users have different path and other settings.
Guoliang Cao