简体   繁体   English

如何在 Swift 中获得标准输入/输出/错误的“管道”?

[英]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.在 Swift 中使用Process时,如果不指定.standardInput.standardOutput.standardError属性,则Process会继承调用者的标准输入/输出/错误,这非常有用。 But let's say that, for example, I want to tell a Process to send its output to the inherited standard error.但是假设,例如,我想告诉Process将其 output 发送到继承的标准错误。 It seems to me I would want to do something like process.standardOutput = ProcessInfo.processInfo.standardError , but ProcessInfo has no standardError property.在我看来,我想做类似process.standardOutput = ProcessInfo.processInfo.standardError的事情,但ProcessInfo没有standardError属性。 How am I supposed to do something like this?我该怎么做这样的事情?

Of course I find the answer to this immediately after posting this question.当然,我在发布此问题后立即找到了答案。

The desired objects are FileHandle.standardInput , FileHandle.standardOutput , and FileHandle.standardError .所需的对象是FileHandle.standardInputFileHandle.standardOutputFileHandle.standardError

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM