私はNSTaskで次のコマンドを実行しようとしています:NSTask実行スクリプト
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
コマンドでは動作しません:
$sudo launchctl load /Users/admin/Library/LaunchAgents/com.devdaily.crontabtest.plist
は、私が使用するコードです。 。これをどうすれば解決できますか?
コンソール以外の環境で 'sudo'を使うのは、パスワードを簡単に入力する方法がないのであまり役に立ちません(標準入力パイプを使うことができますが、OS Xの組み込みエスカレーションユーティリティを使う方がはるかに優れています)。第二に、sudoがパスをロードしていないので、 'sh'によってロードされていないと思います。 –