2
嘗試使用swift腳本在系統中運行可執行文件。我跟着第二個答案here,但是我碰到一個錯誤,抱怨基金會未正確創建:正在運行系統程序和基礎bug
錯誤:
/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中的崇高REPL(Archlinux)。問題:
我做的所有其他小項目都很好,從未發現基金會有錯誤,因爲它在這裏抱怨。我的安裝是否是問題?
有沒有更簡單的方式來運行使用Glibc的可執行文件?