I'm trying to run a Ruby gem called Cupertino (https://github.com/nomad/cupertino) from an Objective-C app. The ios login
command works fine from the terminal.
When I try to run it using an NSTask, I get the following error:
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
require': cannot load such file -- commander/import (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
require' from /Users/Ben/.rvm/gems/ruby-2.1.0/gems/cupertino-0.9.5/bin/ios:3:in `'
If I try to install the gem using rbenv
instead of rvm
, I get this error instead:
/Library/Ruby/Gems/2.0.0/gems/commander-4.1.5/lib/commander/runner.rb:365:in
block in require_program': program version required (Commander::Runner::CommandError) from /Library/Ruby/Gems/2.0.0/gems/commander-4.1.5/lib/commander/runner.rb:364:in
each' from /Library/Ruby/Gems/2.0.0/gems/commander-4.1.5/lib/commander/runner.rb:364:inrequire_program' from /Library/Ruby/Gems/2.0.0/gems/commander-4.1.5/lib/commander/runner.rb:52:in
run!' from /Library/Ruby/Gems/2.0.0/gems/commander-4.1.5/lib/commander/delegates.rb:7:inrun!' from /Library/Ruby/Gems/2.0.0/gems/commander-4.1.5/lib/commander/import.rb:10:in
block in ' /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:inrequire': cannot load such file -- cupertino (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
require' from /Users/Ben/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cupertino-0.9.5/bin/ios:7:in `'
This is the method I am using:
- (void)login {
NSTask* task = [[NSTask alloc] init];
[task setLaunchPath:@"/Users/Ben/.rvm/gems/ruby-2.1.0/gems/cupertino-0.9.5/bin/ios"];
[task setArguments:@[@"login"]];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"task output: %@",string);
[task waitUntilExit];
}
I'm a bit lost - this seems to be some sort of clash between the system version of Ruby and my version. Any ideas on how I can get this up and running?