Shell脚本从目标C(Shell Script from Objective c)

2019-10-23 06:29发布

我怎么能运行使用NSTask以下从客观的命令,

pluginkit -e忽略-i com.xxxxx.Plugin_Id

我试过,但没有奏效,

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

Answer 1:

setLaunchPath应该是你启动二进制文件。 pluginkit位于/usr/bin/ ,所以启动代码应该是这样的,我认为:

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

或用单内衬电话:

system("pluginkit -e ignore -i com.company.pluginId");


文章来源: Shell Script from Objective c