Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jruby run ruby file encoding BUG #3070

Open
zzusunwei opened this issue Jun 19, 2015 · 1 comment
Open

jruby run ruby file encoding BUG #3070

zzusunwei opened this issue Jun 19, 2015 · 1 comment

Comments

@zzusunwei
Copy link

when i use jruby run a ruby file like this :

java:

public static void main(String[] args) {
        ScriptingContainer container = new ScriptingContainer();
        String path = System.getProperty("user.home")+ "/fileOperationDir/Script.rb";//"/Script.rb";
        File file = new File(path);
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);
            container.runScriptlet(inputStream, "");
        } catch (RuntimeException e) {
            String message = e.getMessage();
                System.out.println(message);
        } catch (Exception e) {
            System.out.println("121");
        } finally{
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }

ruby:

begin
    puts "天天动听"
    testlikethis天天动听
rescue Exception => e  
    puts e.message
end  

result
the consle print

天天动听
undefined local variable or method `testlikethis????' for main:Object

but i want get like this :

天天动听
undefined local variable or method `testlikethis天天动听' for main:Object

what should i do???????

@headius
Copy link
Member

headius commented Jul 2, 2015

I believe the problem here is an encoding mismatch. When booting JRuby through ScriptingContainer, perhaps we are not setting a default encoding properly.

Things to check:

  • What is the encoding of your "Script.rb" file?
  • Does it have an encoding comment at the top?
  • What is the default encoding of the host system (e.g. LANG from env)?

Please tell us JRuby version, JVM version, and host OS version as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants