[英]Using launchctl in from NSTask
I want to execute launchctl
from application. 我想从应用程序执行
launchctl
。
For that I am using following code, 为此,我正在使用以下代码,
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/launchctl"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"load ", @"/Users/XYZ/com.XYZ.plist", nil];
[task setArguments: arguments];
[task launch];
It gives me error, launchctl: unknown subcommand "load "
它给我错误,
launchctl: unknown subcommand "load "
However, when I run command from terminal, it executes correctly 但是,当我从终端运行命令时,它可以正确执行
>launchctl load /Users/XYZ/com.XYZ.plist
Whats the difference here and how can it work NSTask? 这有什么区别,它如何工作NSTask?
Remove the trailing space in @"load "
. 删除
@"load "
的尾随空格。
Each object in the array is a single argument for the task. 数组中的每个对象都是任务的单个参数。 There is no need to add spaces to separate the arguments (or to quote the arguments).
无需添加空格来分隔参数(或引用参数)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.