从Swift命令行工具调用xcodebuild失败

从Swift命令行工具调用xcodebuild失败,xcode,swift,cocoa,xcodebuild,nstask,Xcode,Swift,Cocoa,Xcodebuild,Nstask,我正在编写一个简单的swift命令行工具应用程序,它自动化了我的一些iOS开发工作。除了一件事——调用xcodebuild脚本,所有的东西都在工作 我的方法如下所示: func runTest(deviceName: String, os: String) { killAllSimulators() let sdk = "iphonesimulator" let destination = "platform=iOS Simulator,name=

我正在编写一个简单的swift命令行工具应用程序,它自动化了我的一些iOS开发工作。除了一件事——调用xcodebuild脚本,所有的东西都在工作

我的方法如下所示:

func runTest(deviceName: String, os: String) {
        killAllSimulators()
        let sdk = "iphonesimulator"
        let destination = "platform=iOS Simulator,name=" + deviceName + ",OS=" + os
        let arguments = ["-workspace", workspace, "-scheme", scheme, "-sdk", sdk, "-destination", destination, "test"]
        executor.executeCommand("xcodebuild", arguments: arguments)
    }
deviceName等于“iPhone 4s”,os等于“9.0”,正确设置了工作区和方案变量

我的execute命令具有简单的实现:

func executeCommand(command: String, arguments: [String]) -> NSString?  {
        _ = NSProcessInfo.processInfo().processIdentifier
        let pipe = NSPipe()
        let fileHandle = pipe.fileHandleForReading

        let task = NSTask()
        task.launchPath = "/usr/bin/" + command
        task.arguments = arguments
        task.standardOutput = pipe

        task.launch()
        let data = fileHandle.readDataToEndOfFile()
        fileHandle.closeFile()

        return NSString(data: data, encoding: NSUTF8StringEncoding)
    }
我得到一个错误,测试失败了,因为cdtool无法编译。这很奇怪,因为和terminal works调用的脚本完全相同


有什么想法吗?

如果设备名包含空格。println()目的地和参数,则需要引用该设备名,以便可以准确地看到命令,这是基本调试。我猜“iPhone 4s”中的空格是问题所在。我还认为
xcodebuild
也关心当前目录。destination参数是一个字符串,所以是:-destination'platform=iOS Simulator,name=iPhone4s,OS=9.0'。在这种情况下,QuotesGet没有问题:dyld:Symbol未找到:“\u OBJC\u CLASS\u$\ u OS\u对象引用自:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/usr/lib/system/libxpc.dylib,应在:/usr/lib/lib/system/introspection/libdispatch.dylib中/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/usr/lib/system/libxpc.dylib cdtool异常退出如果设备名包含空格。println()目的地和参数,则需要引用该设备名,以便准确地查看命令,这是基本调试。我猜“iPhone 4s”中的空格是问题所在。我还认为
xcodebuild
也关心当前目录。destination参数是一个字符串,所以是:-destination'platform=iOS Simulator,name=iPhone4s,OS=9.0'。在这种情况下,QuotesGet没有问题:dyld:Symbol未找到:“\u OBJC\u CLASS\u$\ u OS\u对象引用自:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/usr/lib/system/libxpc.dylib,应在:/usr/lib/lib/system/introspection/libdispatch.dylib中/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/usr/lib/system/libxpc.dylib cdtool异常退出