Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import Darwin
extension Process {
// See also: https://github.com/apple/swift/blob/9cdbec13eee72feccfc5f8b987882a8c52e8107b/stdlib/private/SwiftPrivate/IO.swift#L84
public struct Stream: OutputStreamType {
private let fd: UnsafeMutablePointer<FILE>
private init(fd: UnsafeMutablePointer<FILE>) {
self.fd = fd
}
public func write(string: String) {
flockfile(fd)
for c in string.utf8 {
putc_unlocked(numericCast(c), fd)
}
funlockfile(fd)
}
}
@_transparent
public static var stdout: Stream {
get {
return Stream(fd: Darwin.stdout)
}
set { }
}
@_transparent
public static var stderr: Stream {
get {
return Stream(fd: Darwin.stderr)
}
set { }
}
}
print("I am an error!", toStream: &Process.stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.