Leaking Pipes with Swift and External Executables

Observed with MacOS 12.4/Xcode 13.4.1/Swift 5

There are quite a lot of tutorials out there covering the basics of running external executables from within Swift and, with very little effort, it’s quite easy to throw together something like this…

import Foundation

let wrappedUname = Process()
wrappedUname.executableURL = URL(fileURLWithPath: "/usr/bin/uname")
wrappedUname.arguments = ["-v"]
let unameOutputPipe = Pipe()
let unameErrorPipe = Pipe()
wrappedUname.standardOutput = unameOutputPipe
wrappedUname.standardError = unameErrorPipe
do{
    try wrappedUname.run()
} catch {
    print("Unexpected error: \(error).")
}
wrappedUname.waitUntilExit()
let unameOutput = String(decoding: unameOutputPipe.fileHandleForReading.readDataToEndOfFile(), as: UTF8.self)
let unameError = String(decoding: unameOutputPipe.fileHandleForReading.readDataToEndOfFile(), as: UTF8.self)
print("Output: " + unameOutput)
print("Error: " + unameError)
Continue reading

The Apple Memory Hole

The (Unofficial) Apple Archive is a newly launched collection of historic Apple media and video.

It must have been a tremendous amount of work collect and catalogue and, for me, the most interesting years are 2004 and 2005 – the years that lead me to purchase my first Mac (and yes, I did buy into PPC after the intel transition was announced!). I doubt it’ll last – Apple’s lawyers must be itching to write takedown notices – but while it’s there it’s an interesting place to poke around.

I still have that old first machine somewhere and I should dig it out; last time I checked (perhaps 5 years ago) it seemed to run ok. I do hope it’s still in something of a functional state.