Search code examples
swiftpipestdiofoundation

How do I get a `Pipe` to the standard input/output/error in Swift?


When using Process in Swift, if you do not specify the .standardInput, .standardOutput, or .standardError properties, the Process inherits the standard input/output/error of the caller, which can be quite useful. But let's say that, for example, I want to tell a Process to send its output to the inherited standard error. It seems to me I would want to do something like process.standardOutput = ProcessInfo.processInfo.standardError, but ProcessInfo has no standardError property. How am I supposed to do something like this?


Solution

  • Of course I find the answer to this immediately after posting this question.

    The desired objects are FileHandle.standardInput, FileHandle.standardOutput, and FileHandle.standardError.