RLT
RLT

Reputation: 4287

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?

Upvotes: 4

Views: 1050

Answers (1)

Martin R
Martin R

Reputation: 539775

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

Upvotes: 7

Related Questions