I want to execute launchctl
from application.
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 "
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?
Remove the trailing space in @"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).