【发布时间】:2017-09-20 11:52:02
【问题描述】:
我正在尝试使用 NSTask 创建一个 Git 提交并向该提交添加一条消息。
这是我尝试过的代码。
NSString *projectPath = @"file:///Users/MYNAME/Desktop/MYPROJECT/";
//stage files
NSPipe *pipe = [NSPipe pipe];
NSTask *task = [[NSTask alloc] init];
task.launchPath = projectPath;
task.arguments = @[@"git", @"add", @"."];
task.standardOutput = pipe;
[task launch];
//commit
NSPipe *pipe2 = [NSPipe pipe];
NSTask *task2 = [[NSTask alloc] init];
task2.launchPath = projectPath;
task2.arguments = @[@"git", @"commit", @"-m",@"\"Some Message\""];
task2.standardOutput = pipe2;
[task2 launch];
我通过使用NSOpenPanel(标准 OS X 打开对话框)收到了projectPath。
在 Xcode 终端中,我收到消息 “启动路径不可访问”
那我做错了什么?
更新 在 Josh Caswell 发表评论后,这是我的代码
NSString *projectPath = @"file:///Users/MYNAME/Desktop/MYPROJECT/";
NSString *gitPath = @"/usr/local/bin/git"; //location of the GIT on my mac
//stage
NSPipe *pipe = [NSPipe pipe];
NSTask *task = [[NSTask alloc] init];
task.launchPath = gitPath;
task.currentDirectoryPath = projectPath;
task.arguments = @[@"add", @"."];
task.standardOutput = pipe;
[task launch];
[任务启动]之后;我在终端中收到错误消息“工作目录不存在。”
【问题讨论】:
-
对于那些启用应用沙盒的人来说真正的答案stackoverflow.com/questions/7018354/remove-sandboxing
-
对于那些启用了应用沙盒的人来说真正的答案stackoverflow.com/questions/7018354/remove-sandboxing
标签: objective-c cocoa nstask