【发布时间】:2017-08-19 04:25:47
【问题描述】:
尝试使用 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 运行它。问题:
我所做的所有其他小项目都运行良好,从未发现 Foundation 出现错误,因为它在这里抱怨。是我的安装问题吗?
有没有更简单的方法来使用 Glibc 运行可执行文件?
【问题讨论】:
标签: swift linux sublimetext3 archlinux