Executing shell commands with NSTask - Objective-C Cocoa

后端 未结 1 1417
攒了一身酷
攒了一身酷 2020-12-01 06:35

I have been searching for days and hours for this, I have seen a lot of examples of this, but cannot figure out how NSTask works, let\'s say I wanted to exe

相关标签:
1条回答
  • 2020-12-01 07:09

    You could do something like:

    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath:@"/bin/bash"];
    [task setArguments:@[ @"-c", @"/usr/bin/killall Dock" ]];
    [task launch];
    

    Exactly what launch path and arguments you provide are dictated by the command you want to run and its parameters.

    0 讨论(0)
提交回复
热议问题