3

我已经坚持了一段时间了。我正在尝试从我的可可应用程序运行 rails shell 命令来创建一个新闻 rails 应用程序。当我跑

~/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/bin/rails new projectname

我能够创建一个新项目。但是如果我运行这样的东西

NSString *path = @"~/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/bin/rails";
NSString *script = [NSString stringWithFormat:@"%@ new ~/Desktop/testapp", path];
system([script UTF8String]);

或这个

- (IBAction)buildProject:(NSButton *)sender 
{
NSString *path = @"~/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/bin/rails";
NSArray *args = [NSArray arrayWithObjects:@"new", @"~/Desktop/testapp", nil];

NSTask *task = [NSTask new];
[task setLaunchPath:path];
[task setArguments:args];
[task launch];
}

我收到以下错误

/Users/dylanross/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/bin/rails:7:in `require': no such file to load -- rails/cli (LoadError)
from /Users/dylanross/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/bin/rails:7
4

1 回答 1

0

我遇到了类似的问题,因为我使用/bin/sh的是 launchPath。

试试这个快速代码。

let task = NSTask()
task.launchPath = "/bin/bash"
let fileToRun = "/Users/johndoe/Desktop/testapp/app.rb"
task.arguments = ["-l", "rvm-auto-ruby", fileToRun]
let pipe = NSPipe()
task.standardOutput = pipe
task.launch()
于 2014-07-26T06:26:13.957 回答