S
S
shadeofpast2015-02-02 06:54:43
ruby
shadeofpast, 2015-02-02 06:54:43

Calling a shell command containing Russian characters in ruby?

Good afternoon.
Calling a console command

cmd = '/usr/bin/mediainfo "/var/avalon/dropbox/Лекции_для_молодых_ученых/Nabiullin_SciERes_1.flv" --Output=XML'
out = `#{cmd}`

in a specific rails project (avalon media system, ruby ​​2.1.5, rails 3.3.2), where the file path contains Russian letters, returns code 1 (probably file not found). If you remove Russian letters from the path, then everything is fine.
If you call another program (for example `head "/var/avalon/dropbox/Lectures_for_young_scientists/Nabiullin_SciERes_1.flv"`) - everything is ok. If you call the first command in irb (or in the project environment) - everything is ok.
IMHO, the problem is in the encoding.
Question - how to solve it?)
Details:
When trying to add a file to the collection with Russian characters in the avalon media system , an error is raised in the file line 543. Which refers us to calling an external console command in the media info gem infile line 473.
Using this gem in irb succeeds. File path encoding utf-8. Console encoding is utf-8.
Damn magic.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shadeofpast, 2015-02-02
@shadeofpast

The problem is that for avalon ENV["LANG"] = С.
ENV["LANG"]='en_US.utf-8'solved a problem.
Thanks to all.

A
Alexey Shein, 2015-02-02
@conf

Seems to be a bug in mediainfo . Is it working fine locally? What OS?
Try it step by step:
1) Check the command manually in the console (bash)
2) Check the operation of the gem in the rails console, and not just in irb, some gems may conflict: bundle exec rails c
3) Check the encoding of the string with the file name (conveniently do it through the pry-rails gem, put binding.pry in the right place and debug it)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question