Re: Running Ruby interpreter in subshell (OS X)

Brian Marick <[email protected]> Thu, 6 Jun 2002 08:34:19 -0500
Newsgroups gmane.emacs.macintosh.user
Message-ID <p05111b00b9247e59e248@[63.57.3.28]>
At 3:59 PM -0600 6/5/02, Andrew Choi wrote:
>Hi Brian,
>
>>  I can't seem to run the Ruby interpreter as a subshell on OS
>>  X. (Ruby is a language kind of like Python.)
>>
>>  Ruby comes with some .el files that define M-x run-ruby (and all the
>>  usual sub-interpreter commands you'd expect). It works as expected
>>  with the dumb-terminal version of emacs that comes with OS X. M-x
>>  run-ruby doesn't work with the flashier emacs I downloaded (details
>>  below). Other kinds of subshells work.
>>
>>  The symptom is that when I M-x run-ruby, I get an empty buffer,
>>  rather than a prompt.  [...]
>
>Could you please try setting the PATH environment variable as
>suggested by others on the mailing list about a week ago for a similar
>question on Python?  This is necessary since an application started
>from the Finder does not get the same environment variables set when
>started from a shell.  I suppose you may also need to set certain Lisp
>variables in the Ruby package.

I don't think it's the path problem. Before the python notes, I did this:

(setq exec-path (append exec-path '("/usr/local/bin" "~/bin")))

Although that doesn't give "shell-command" the right path, it does 
suffice to have make-comint find things in /usr/local/bin and ~/bin.

I tonight added
(setq shell-file-name "tcsh")
so that M-! would get the right path. This does not help with my problem.

I also tried the plist solution, but that didn't work at all. (See 
"digression", below.)

I've done some playing around, and I suspect what's happening is that 
the Ruby interpreter is exiting immediately (for whatever reason). 
Emacs seems to be behaving oddly when given a program that exits 
without taking input. Consider this program:

main() {
   int i;
   for (i = 0; i < 10; i++)
     printf("hello, world\n");
   exit(42);
}

I invoke it with this:

(defun test-run (cmd)
   (interactive "sCMD: ")
   (pop-to-buffer (make-comint "ruby" cmd)))

(which is the core of what "M-x run-ruby" does).

If I invoke it when no *ruby* buffer exists, one of three things will 
happen. In all cases, no text appears in the *ruby* buffer.
1) most often, the status is immediately "exit".
2) less often, the status starts as "run", then changes to "exit" in 
a second or so.
3) much less often, the status stays as run until I do something, 
such as press an inserting key or leave the buffer with "C-x o".

All these cases differ from the emacs that comes with OS X, which always prints
"Process ruby exited abnormally with code 42" (but has nothing else 
in the buffer).

If (back in the version I want to be using), I invoke the test 
command when a *ruby* buffer already exists, I always get this:

Process ruby<2> killed

Process ruby killed

Process ruby killed

To complicate things, change the loop iteration to 100. Then I get 
the following, no matter whether I'm going to a new buffer or reusing 
an old one:

hello, world
hello, world
<...>
hello, world
hello, world
hello, wor

It always stops in the same place in the final line.

The stock OS X version stops in the same place in the line, but then 
prints the line about the exit code.

How is Emacs supposed to behave with lots of output and no input?

Is there a way to get all the output from a command, so that I can 
see if irb (the ruby interpreter) prints any useful diagnostics? What 
I thought of doing was running it with shell-command, but that brings 
up the spinning beach ball, and I have to Force Quit emacs. Another 
way to cause the beach ball is to use M-! to invoke this:

while true
do
   read foo
   echo $foo
done

Given that Ruby runs in a Terminal window (not under emacs), and that 
it runs when invoked from the command line in a M-x shell, what could 
be causing it to not be accepting input? It does take input from 
stdin:

[localhost:~] marick% echo "exit" | irb
irb(main):001:0> exit
[localhost:~] marick%

Note that it echoes the command.

------------ <digression> --------------
The plist solution didn't work at all. I put this in 
~/.MacOSX/environment.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
	<key>HOME</key>
	<string>/Users/marick</string>
	<key>FOO</key>
	<string>bar</string>
	<key>PATH</key>
	<string>/usr/bin:/bin:/Users/marick:/usr/local/bin:/Users/marick/bin:/Users/marick/src/ruby/ruby-trace/bin</string>
</dict>
</plist>

That doesn't change the PATH in either Emacs, as checked with "M-! 
which". (I put the FOO environment variable in to check if it's 
visible in either Emacs or the Terminal shell. Nope.)

Do I have the right filename?
------------ </digression> --------------

-- 
--
If this mail message is supposed to have an attachment, doesn't seem 
to, and you use Outlook to read mail: you've probably been bitten by 
an Outlook bug. The attachment is really there, Outlook just isn't 
showing it to you. You can still save it with File | Save 
Attachments. (If that doesn't work, I must have forgotten to attach 
the file.) I'm sorry my choice of a Macintosh and the Eudora mailer 
is an inconvenience to you.


"Act always so as to increase the number of choices." -- Heinz von Foerster

--
Brian Marick, [email protected]
www.testing.com - Software testing services and resources
www.testingcraft.com - Where software testers exchange techniques
www.visibleworkings.com - Adequate understanding of system internals

_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm