Shell Script from Objective c

2019-08-09 01:56发布

How can i run following command from objective using NSTask,

pluginkit -e ignore -i com.xxxxx.Plugin_Id

I tried this but not worked,

NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath:@"/bin/sh"];
   [task setArguments: @[@"pluginkit",@"-e",@"ignore",@"-i",@"com.xxxxx.Plugin_Id"]];
    [task launch];

1条回答
Luminary・发光体
2楼-- · 2019-08-09 02:25

setLaunchPath should be the binary you launching. pluginkit is located on /usr/bin/, so the launch code should be like this i think:

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/pluginkit"];
[task setArguments: @[@"-e", @"ignore", @"-i", @"com.company.pluginId"]];
[task launch];
[task waitUntilExit];

or with a single lined call:

system("pluginkit -e ignore -i com.company.pluginId");
查看更多
登录 后发表回答