运行系统程序和Foundation bug

Running system program and Foundation bug

正在尝试使用 swift 脚本来 运行 系统中的可执行文件。我遵循了第二个答案 here,但是我 运行 遇到了一个错误,抱怨 Foundation 没有正确构建:

错误:

/usr/lib/swift/CoreFoundation/CoreFoundation.h:25:10: note: while building module 'SwiftGlibc' imported from /usr/lib/swift/CoreFoundation/CoreFoundation.h:25:
#include <sys/types.h>
         ^

代码:

import Foundation

func execCommand(command: String, args: [String]) -> String {
    if !command.hasPrefix("/") {
        let commandFull = execCommand(command: "/usr/bin/which", args: [command]).trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
        return execCommand(command: commandFull, args: args)
    } else {
        let proc = Process()
        proc.launchPath = command
        proc.arguments = args
        let pipe = Pipe()
        proc.standardOutput = pipe
        proc.launch()
        let data = pipe.fileHandleForReading.readDataToEndOfFile()
        return String(data: data, encoding: String.Encoding.utf8)!
    }
}

let commandOutput = executeCommand("/bin/echo", ["Hello, I am here!"])
println("Command output: \(commandOutput)")

我正在 运行使用 Linux (Archlinux) 中的 Sublime REPL 进行此操作。问题:

回答我自己的问题。这似乎是 swift 的 Sublime REPL 中的一个错误,因为 运行 在命令行中使用它使代码 运行 没有问题。此外,未更新到 Swift 3 的代码存在一些问题,下面是传递代码。我仍然想找到一种使用 Glibc 在 Swift 中 运行ning 可执行文件的方法。

#! /usr/bin/swift

import Foundation

func execCommand(command: String, args: [String]) -> String {
    if !command.hasPrefix("/") {
        let commandFull = execCommand(command: "/usr/bin/which", args: [command]).trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
        return execCommand(command: commandFull, args: args)
    } else {
        let proc = Process()
        proc.launchPath = command
        proc.arguments = args
        let pipe = Pipe()
        proc.standardOutput = pipe
        proc.launch()
        let data = pipe.fileHandleForReading.readDataToEndOfFile()
        return String(data: data, encoding: String.Encoding.utf8)!
    }
}

let commandOutput = execCommand(command:"/bin/echo", args:["Hello, I am here!"])
print("Command output: \(commandOutput)")