Marcelo de Moraes Serpa <celose...@gmail.com> wrote: > Hey list, > > I've tried posting on help-gnu-emacs mailing list first, but not luck so far, > so I thought I'd try here, as I know there are many savvy emacs users around. > > I have a small Ruby CLI program that I want to call from emacs. This script > simply opens an emacs orgmode file from a specific location in my hard drive, > and does some text processing. When I call it from the terminal directly, it > works fine. When I call it from emacs, the > script fails with an encoding error. > > I'm using this elisp to call it from emacs after a buffer is saved: > > (defun test () > (let ((universal-coding-system-argument 'utf-8-unix)) > (shell-command "/Users/myself/.rvm/bin/rvm ruby-1.9.3-p194 do > /usr/bin/myrubyscript") > )) > (add-hook 'after-save-hook 'test) > > NOTE: The (let ((universal-coding-system-argument 'utf-8-unix)) was an > attempt to fix it, but it made no difference whatsoever. >
Probably wrong, but who knows? it may work by some miracle: (let ((coding-system-for-read 'utf-8-unix) (coding-system-for-write 'utf-8-unix)) (shell-command "/Users/myself/.rvm/bin/rvm ruby-1.9.3-p194 do /usr/bin/myrubyscript") > After I save a buffer, the shell-command function is fired, but I get the > following output in the "*Shell Command Output*" buffer: > > F, [2012-08-30T01:59:18.688827 #94004] FATAL -- : invalid byte sequence > in US-ASCII (ArgumentError) > > /Users/myself/.rvm/gems/ruby-1.9.3-p194/gems/org-ruby-0.6.3/lib/org-ruby/parser.rb:89:in > `split' > > /Users/myself/.rvm/gems/ruby-1.9.3-p194/gems/org-ruby-0.6.3/lib/org-ruby/parser.rb:89:in > `initia > But this looks like ruby is expecting ASCII and is getting something else (probably UTF-8). What does the output of the command, when executed from a terminal, look like? Redirect it into a file and then use od to look at bytes. Also, you can try adding an output buffer as argument to the shell-command and then eyeballing the output in that buffer to see if it matches the terminal output. Nick > The strange thing is that the file that this script opens *is* accessible, > and is the same file it would open if it were fired up from the terminal. For > some reason, Emacs is getting in the way, but I have no idea what that could > be. Am I missing something? If someone could > enlighten me here, I'd be really grateful! > > Thanks in advance, > > - Marcelo. > > > ---------------------------------------------------- > Alternatives: > > ----------------------------------------------------