在我的NSApplication中,我有一个按钮。当我点击它时,我想启动/启动一个守护进程/代理。我该怎么办?我已经尝试过了:
- (void) runAgent {
NSTask *task = [[NSTask alloc] init];
task.launchPath = @"launchctl load /System/Library/LaunchAgents/com.mycompany.myagent.plist";
[task setLaunchPath:@"/bin/sh"];
[task launch];
}
没有成功......
答案 0 :(得分:1)
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/launchctl"];
[task setArguments:[NSArray arrayWithObjects:@"load",@"/System/Library/LaunchAgents/com.mycompany.myagent.plist", nil]];
[task launch];