문제

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top