Created
July 11, 2016 20:07
-
-
Save zwaldowski/4ed2fd48da2af3193b0cbd3ec1883c9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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