Ruby Readline Fails If Process Started with Arguments

Ruby readline fails if process started with arguments

Have you tried while (l = $stdin.gets.chomp!)? Otherwise Kernel#gets reads from ARGV.

Trouble Installing Ruby 1.9.2 on OSX - Readline and Make errors

Are you compiling Readline from source? It might be less painful to compile and install Readline via Homebrew, assuming that you have at least one working version of Ruby on your system.

Once you've done that, you can try the RVM install of Ruby 1.9.2 again, and it should skip the Readline compilation step.

Updated in response to comment:

So you are using a Homebrew installed Readline. In that case, find out where the new (less broken) Readline libs are installed, and try passing the location of that version of Readline to the RVM install process. Something like:

rvm install ruby-1.9.2-p320 -C
--with-readline-dir=/usr/local/Cellar/readline/6.2.1

Clearly, your directory will be slightly different the one in my example.

rspec issue believed to be with gets.chomp call

The reason is that gets reads from ARGV (argument variables), such as the -fd flag you're giving to rpsec.

You can recreate this situation pretty easily:

> ruby -e "puts gets.chomp" ASD
-e:1:in `gets': No such file or directory @ rb_sysopen - ASD (Errno::ENOENT)
from -e:1:in `gets'
from -e:1:in `<main>'

You can prevent this from happening by clearing out ARGV before calling gets.

> ruby -e "ARGV.clear; puts gets.chomp" ASD
asd # <-- I then type this
asd # <-- and this is printed

You can't just say ARGV = [] because it's a constant, but calling clear is fine because it's not redefining the variable.

In short, just put this somewhere before gets.chomp:

ARGV.clear

Here's another question on the topic: Ruby readline fails if process started with arguments

rails console require cannot load such file readline

Readline gem is required by your application but not specified in your Gemfile

Please add this to your gem file

gem 'rb-readline' 

Also reinstall

libreadline-dev

Ruby script that sets environment variable fails with Invalid argument - ruby_setenv (Errno::EINVAL) when started from a Java process on Windows

The problem was that when I started the Ruby script from Eclipse I had a different environment. Specifically, I had a CLASSPATH environment variable that looked really strange. I think the cause of this is the size of the CLASSPATH variable. It is really really long before being passed on to my sub process but within the sub process it is truncated and looks broken.

I am suspecting I am running into problems with the max size of the Windows environment block (see details here: http://blogs.msdn.com/b/oldnewthing/archive/2010/02/03/9957320.aspx). I will not investigate this further but have fixed my code to remove the CLASSPATH variable before starting the process.

Path path = FileSystems.getDefault().getPath("c:", "temp", "rb-test");
ProcessBuilder pb = new ProcessBuilder("ruby.exe","foo.rb").directory(path.toFile()).redirectErrorStream(true);
pb.environment().remove("CLASSPATH");
Process process = pb.start();
process.waitFor();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = bufferedReader.readLine();
while (line != null) {
System.out.println(line);
line = bufferedReader.readLine();
}

Rails: Having trouble running Rails console

According to the error logs, looks like you are missing libreadline installed on your machine. Could you try this link to install readline on your Mac.

Rails Console error after upgrading to Ubuntu 18.04

You need to make sure readline is installed. You're using RVM, so you can run:

rvm requirements

and it should help make sure you have everything installed that you need, followed by:

rvm reinstall 2.4.1

if needed to make sure your ruby is good to go.



Related Topics



Leave a reply



Submit