Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Using launchctl in from NSTask

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?

like image 483
RLT Avatar asked Mar 24 '23 07:03


1 Answers

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

like image 117
Martin R Avatar answered Apr 01 '23 11:04

Martin R