From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: [OT] Encoding error when calling a ruby script from Emacs using shell-command Date: Fri, 31 Aug 2012 15:51:28 -0400 Message-ID: <7522.1346442688@alphaville> References: Reply-To: nicholas.dokos@hp.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:46769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7XFb-0000dM-CI for emacs-orgmode@gnu.org; Fri, 31 Aug 2012 15:51:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T7XFa-0000CV-7y for emacs-orgmode@gnu.org; Fri, 31 Aug 2012 15:51:31 -0400 Received: from g6t0184.atlanta.hp.com ([15.193.32.61]:24466) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7XFa-0000CE-2L for emacs-orgmode@gnu.org; Fri, 31 Aug 2012 15:51:30 -0400 In-Reply-To: Message from Marcelo de Moraes Serpa of "Thu\, 30 Aug 2012 22\:42\:14 CDT." List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Marcelo de Moraes Serpa Cc: Org Mode Marcelo de Moraes Serpa wrote: > Hey list, >=20 > 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. >=20 > I have a small Ruby CLI program that I want to call from emacs.=C2=A0This= script simply opens an emacs orgmode file from a specific location in my h= ard drive, and does some text processing.=C2=A0When I call it from the term= inal directly, it works fine. When I call it from emacs, the > script fails with an encoding error. >=20 > I'm using this elisp to call it from emacs after a buffer is saved: >=20 > (defun test () > =C2=A0 (let ((universal-coding-system-argument 'utf-8-unix)) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 (shell-command =C2=A0"/Users/myself/.rvm/= bin/rvm ruby-1.9.3-p194 do /usr/bin/myrubyscript") > =C2=A0 =C2=A0 )) > (add-hook 'after-save-hook 'test) >=20 > NOTE: The (let ((universal-coding-system-argument 'utf-8-unix)) was an at= tempt to fix it, but it made no difference whatsoever. >=20 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/my= rubyscript") > After I save a buffer, the shell-command function is fired, but I get the= following output in the "*Shell Command Output*" buffer: >=20 > F, [2012-08-30T01:59:18.688827 #94004] FATAL -- : invalid byte sequen= ce in US-ASCII (ArgumentError) > /Users/myself/.rvm/gems/ruby-1.9.3-p194/gems/org-ruby-0.6.3/lib/org-r= uby/parser.rb:89:in `split' > /Users/myself/.rvm/gems/ruby-1.9.3-p194/gems/org-ruby-0.6.3/lib/org-r= uby/parser.rb:89:in `initia >=20 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 li= ke? 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! >=20 > Thanks in advance, >=20 > - Marcelo. >=20 >=20 > ---------------------------------------------------- > Alternatives: >=20 > ----------------------------------------------------