我正在尝试使用 NSTask 运行以下命令:
$sudo launchctl load /Users/admin/Library/LaunchAgents/com.devdaily.crontabtest.plist
下面是我使用的代码:
NSTask *server = [NSTask new];
[server setLaunchPath:@"/bin/launchctl"];
[server setArguments:[NSArray arrayWithObjects:@"load",@"com.devdaily.crontabtest.plist",nil]];
[server setCurrentDirectoryPath:@"/Users/admin/Library/LaunchAgents/"];
NSPipe *outputPipe = [NSPipe pipe];
[server setStandardInput:[NSPipe pipe]];
[server setStandardOutput:outputPipe];
[server launch];
[server waitUntilExit]; // Alternatively, make it asynchronous.
[server release];
sudo
但是,由于命令,它不起作用。我怎样才能解决这个问题?