如何从我的Cocoa应用程序在终端中运行命令?

问题描述:

我想使用乐器通过我的可爱应用程序在我的iOS模拟器上安装.app。

I want to use instrument to install the .app on my iOS simulator through my cocoa app.

这是我第一次开发可可应用程序和NSTask。
NSTask需要一个启动路径,在我的情况下是不相关的,因为这个命令可以从任何地方运行。
这是我想运行的命令:

This is my first time developing a cocoa app and also NSTask. NSTask requires a launch path which in my case is irrelevant as this command can be run from anywhere. This is the command i want to run:

instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/ AutomationInstrument.xrplugin / Contents / Resources / Automation.tracetemplate -wiPad Retina(7.1 Simulator)

instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -w "iPad Retina (7.1 Simulator)" ""

目前我有这个:

NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath:@"/"];

    NSString * commandTorun = @"instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate  -w \"iPad Retina (7.1 Simulator)\" \"<path to .app>" ";

    NSArray *arguments = [NSArray arrayWithObjects:
                          @"-t" ,
                          [NSString stringWithFormat:@"%@", commandTorun],
                          nil];

    NSLog(@"Run command:%@",commandTorun);
[task setArguments:arguments];
[task launch];

任何帮助将不胜感激。

感谢,

这里我们走了。


XCode 7.3
iPhone 6(9.3)

Working solution. XCode 7.3 iPhone 6 (9.3)

 NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath: @"/Applications/Xcode 7.3.app/Contents/Developer/usr/bin/instruments"];
    NSArray *arguments = [NSArray arrayWithObjects:
                          @"-t",
                          @"/Applications/Xcode 7.3.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate",
                          @"-w",
                          @"iPhone 6 (9.3)",
                          @"/Users/ab56353/Desktop/FirstTest.app",
                          @"-e",
                          @"UIASCRIPT",
                          @"/Users/ab56353/Desktop/TapGeneration.js",
                          nil];
    [task setArguments:arguments];
    [task launch];

注意:如果物理设备)。

Note: Place the proper xcode app name(/Applications/xcode 7.3) and simulator or device udid (if physical device).