Gentle Intro to Swift for TensorFlow

in case someone stumbles upon this thread and finds out the link returns a 404:

SwiftAI (not stable but not a dev repo) - 00_load_data.ipynb
:

//export
public extension String {
    @discardableResult
    func shell(_ args: String...) -> String
    {
        let (task,pipe) = (Process(),Pipe())
        task.executableURL = URL(fileURLWithPath: self)
        (task.arguments,task.standardOutput) = (args,pipe)
        do    { try task.run() }
        catch { print("Unexpected error: \(error).") }

        let data = pipe.fileHandleForReading.readDataToEndOfFile()
        return String(data: data, encoding: String.Encoding.utf8) ?? ""
    }
}

print("/bin/ls".shell("-lh"))
1 Like