* Encoding error when calling a ruby script from Emacs using shell-command
@ 2012-08-30 17:40 Marcelo de Moraes Serpa
2012-08-30 17:41 ` Marcelo de Moraes Serpa
0 siblings, 1 reply; 6+ messages in thread
From: Marcelo de Moraes Serpa @ 2012-08-30 17:40 UTC (permalink / raw
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1400 bytes --]
Hi list,
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 'us-ascii-mac))
> (shell-command "/Users/myself/.rvm/bin/rvm ruby-1.9.3-p194 do
> /usr/bin/myrubyscript")
> ))
> (add-hook 'after-save-hook 'test)
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
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.
[-- Attachment #2: Type: text/html, Size: 2098 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding error when calling a ruby script from Emacs using shell-command
2012-08-30 17:40 Encoding error when calling a ruby script from Emacs using shell-command Marcelo de Moraes Serpa
@ 2012-08-30 17:41 ` Marcelo de Moraes Serpa
2012-08-30 21:16 ` Peter Dyballa
0 siblings, 1 reply; 6+ messages in thread
From: Marcelo de Moraes Serpa @ 2012-08-30 17:41 UTC (permalink / raw
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1731 bytes --]
By the way, I forgot to say that I have added the "(let
(universal-coding-system-argument 'us-ascii-mac))" in an attempt to fix it,
but it made no difference whatsoever.
-Marcelo.
On Thu, Aug 30, 2012 at 12:40 PM, Marcelo de Moraes Serpa <
celoserpa@gmail.com> wrote:
> Hi list,
>
> 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 'us-ascii-mac))
>> (shell-command "/Users/myself/.rvm/bin/rvm ruby-1.9.3-p194 do
>> /usr/bin/myrubyscript")
>> ))
>> (add-hook 'after-save-hook 'test)
>
>
> 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
>
>
> 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.
>
>
[-- Attachment #2: Type: text/html, Size: 2668 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding error when calling a ruby script from Emacs using shell-command
2012-08-30 17:41 ` Marcelo de Moraes Serpa
@ 2012-08-30 21:16 ` Peter Dyballa
2012-08-30 23:01 ` Marcelo de Moraes Serpa
0 siblings, 1 reply; 6+ messages in thread
From: Peter Dyballa @ 2012-08-30 21:16 UTC (permalink / raw
To: Marcelo de Moraes Serpa; +Cc: help-gnu-emacs
Am 30.08.2012 um 19:41 schrieb Marcelo de Moraes Serpa:
> By the way, I forgot to say that I have added the "(let
> (universal-coding-system-argument 'us-ascii-mac))" in an attempt to fix it,
> but it made no difference whatsoever.
Have you tried an UTF encoding? I think Ruby isn't as primitive as US-ASCII…
--
Greetings
Pete
We are usually convinced more easily by reasons we have found ourselves than by those which have occurred to others.
– Blaise Pascal
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding error when calling a ruby script from Emacs using shell-command
2012-08-30 21:16 ` Peter Dyballa
@ 2012-08-30 23:01 ` Marcelo de Moraes Serpa
2012-08-31 22:18 ` Marcelo de Moraes Serpa
0 siblings, 1 reply; 6+ messages in thread
From: Marcelo de Moraes Serpa @ 2012-08-30 23:01 UTC (permalink / raw
To: Peter Dyballa; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 785 bytes --]
Hi Peter,
Thanks for the reply.
I've changed the func argument to 'utf-8-unix and it did not make a
difference. Same error.
- Marcelo.
On Thu, Aug 30, 2012 at 4:16 PM, Peter Dyballa <Peter_Dyballa@web.de> wrote:
>
> Am 30.08.2012 um 19:41 schrieb Marcelo de Moraes Serpa:
>
> > By the way, I forgot to say that I have added the "(let
> > (universal-coding-system-argument 'us-ascii-mac))" in an attempt to fix
> it,
> > but it made no difference whatsoever.
>
> Have you tried an UTF encoding? I think Ruby isn't as primitive as
> US-ASCII…
>
> --
> Greetings
>
> Pete
>
> We are usually convinced more easily by reasons we have found ourselves
> than by those which have occurred to others.
> – Blaise Pascal
>
>
[-- Attachment #2: Type: text/html, Size: 1183 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding error when calling a ruby script from Emacs using shell-command
2012-08-30 23:01 ` Marcelo de Moraes Serpa
@ 2012-08-31 22:18 ` Marcelo de Moraes Serpa
2012-08-31 22:40 ` Peter Dyballa
0 siblings, 1 reply; 6+ messages in thread
From: Marcelo de Moraes Serpa @ 2012-08-31 22:18 UTC (permalink / raw
To: Peter Dyballa; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1478 bytes --]
Alright, I solved it.
The problem is that emacs' shell-command doesn't use the same environment,
so it wasn't picking up the value of those three vars:
✗ export | grep UTF
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
So, I did this:
(defun test ()
(setenv "LANG" "en_US.UTF-8")
(setenv "LC_ALL" "en_US.UTF-8")
(setenv "LC_CTYPE" "en_US.UTF-8")
(shell-command "/Users/myself/.rvm/bin/rvm ruby-1.9.3-p194 do
/usr/bin/rubyscript")
)
And now it works fine.
Cheers,
- Marcelo.
On Thu, Aug 30, 2012 at 6:01 PM, Marcelo de Moraes Serpa <
celoserpa@gmail.com> wrote:
> Hi Peter,
>
> Thanks for the reply.
>
> I've changed the func argument to 'utf-8-unix and it did not make a
> difference. Same error.
>
> - Marcelo.
>
>
> On Thu, Aug 30, 2012 at 4:16 PM, Peter Dyballa <Peter_Dyballa@web.de>wrote:
>
>>
>> Am 30.08.2012 um 19:41 schrieb Marcelo de Moraes Serpa:
>>
>> > By the way, I forgot to say that I have added the "(let
>> > (universal-coding-system-argument 'us-ascii-mac))" in an attempt to fix
>> it,
>> > but it made no difference whatsoever.
>>
>> Have you tried an UTF encoding? I think Ruby isn't as primitive as
>> US-ASCII…
>>
>> --
>> Greetings
>>
>> Pete
>>
>> We are usually convinced more easily by reasons we have found ourselves
>> than by those which have occurred to others.
>> – Blaise Pascal
>>
>>
>
[-- Attachment #2: Type: text/html, Size: 3209 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding error when calling a ruby script from Emacs using shell-command
2012-08-31 22:18 ` Marcelo de Moraes Serpa
@ 2012-08-31 22:40 ` Peter Dyballa
0 siblings, 0 replies; 6+ messages in thread
From: Peter Dyballa @ 2012-08-31 22:40 UTC (permalink / raw
To: Marcelo de Moraes Serpa; +Cc: help-gnu-emacs
Am 01.09.2012 um 00:18 schrieb Marcelo de Moraes Serpa:
> The problem is that emacs' shell-command doesn't use the same environment,
> so it wasn't picking up the value of those three vars:
>
> ✗ export | grep UTF
> LANG=en_US.UTF-8
> LC_ALL=en_US.UTF-8
> LC_CTYPE=en_US.UTF-8
>
> So, I did this:
>
> (defun test ()
> (setenv "LANG" "en_US.UTF-8")
> (setenv "LC_ALL" "en_US.UTF-8")
> (setenv "LC_CTYPE" "en_US.UTF-8")
> (shell-command "/Users/myself/.rvm/bin/rvm ruby-1.9.3-p194 do
> /usr/bin/rubyscript")
> )
There are more options…
When you want GNU Emacs to run in an en_US.UTF-8 environment you can either use the three setenv statements in you init file or make the system use this to launch GNU Emacs:
env LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 emacs … &
If you want to restrict en_US.UTF-8 for the Ruby sub-shell you could also use without the setenv statements:
(shell-command "env LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /Users/myself/.rvm/bin/rvm ruby-1.9.3-p194 do /usr/bin/rubyscript")
The best option, IMO, is though to set in your login script (~/.profile or ~/.bash_profile) the en_US.UTF-8 environment. Then you'd have this available everywhere: in shells inside terminal emulations, the X Windows system, and its clients.
--
Greetings
Pete
One cannot live by television, video games, top ten CDs, and dumb movies alone.
– Amiri Baraka, 1999
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-08-31 22:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-30 17:40 Encoding error when calling a ruby script from Emacs using shell-command Marcelo de Moraes Serpa
2012-08-30 17:41 ` Marcelo de Moraes Serpa
2012-08-30 21:16 ` Peter Dyballa
2012-08-30 23:01 ` Marcelo de Moraes Serpa
2012-08-31 22:18 ` Marcelo de Moraes Serpa
2012-08-31 22:40 ` Peter Dyballa
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.