Process.RunAndCaptureTextAsync 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
| 名称 | 说明 |
|---|---|
| RunAndCaptureTextAsync(ProcessStartInfo, CancellationToken) |
异步启动所 |
| RunAndCaptureTextAsync(String, IEnumerable<String>, CancellationToken) |
异步启动具有指定文件名和可选参数的进程,捕获其标准输出和错误,等待它退出,并返回捕获的文本和退出状态。 |
RunAndCaptureTextAsync(ProcessStartInfo, CancellationToken)
- Source:
- Process.Scenarios.cs
异步启动所 startInfo描述的过程,捕获其标准输出和错误,等待其退出,并返回捕获的文本和退出状态。
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Threading.Tasks.Task<System.Diagnostics.ProcessTextOutput> RunAndCaptureTextAsync(System.Diagnostics.ProcessStartInfo startInfo, System.Threading.CancellationToken cancellationToken = default);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member RunAndCaptureTextAsync : System.Diagnostics.ProcessStartInfo * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Diagnostics.ProcessTextOutput>
Public Shared Function RunAndCaptureTextAsync (startInfo As ProcessStartInfo, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ProcessTextOutput)
参数
- startInfo
- ProcessStartInfo
ProcessStartInfo包含用于启动进程的信息。
- cancellationToken
- CancellationToken
用于取消异步操作的令牌。 如果令牌已取消,则进程将终止。
返回
表示异步作的任务。 任务的值包含捕获的文本输出和进程的退出状态。
- 属性
例外
startInfo 是 null。
cancellationToken读取重定向的流时取消了该操作。
注解
如果在读取重定向流时发生取消,该方法将尝试终止进程并引发 OperationCanceledException。 如果在完全读取流后发生取消,但在等待进程退出时,将终止进程,并且返回的进程已
适用于
RunAndCaptureTextAsync(String, IEnumerable<String>, CancellationToken)
- Source:
- Process.Scenarios.cs
异步启动具有指定文件名和可选参数的进程,捕获其标准输出和错误,等待它退出,并返回捕获的文本和退出状态。
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Threading.Tasks.Task<System.Diagnostics.ProcessTextOutput> RunAndCaptureTextAsync(string fileName, System.Collections.Generic.IEnumerable<string>? arguments = default, System.Threading.CancellationToken cancellationToken = default);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member RunAndCaptureTextAsync : string * seq<string> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Diagnostics.ProcessTextOutput>
Public Shared Function RunAndCaptureTextAsync (fileName As String, Optional arguments As IEnumerable(Of String) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ProcessTextOutput)
参数
- fileName
- String
要启动的可执行文件的名称。
- arguments
- IEnumerable<String>
要传递给进程的命令行参数。 传递 null 或空序列以启动进程,而无需其他参数。
- cancellationToken
- CancellationToken
用于取消异步操作的令牌。 如果令牌已取消,则进程将终止。
返回
表示异步作的任务。 任务的值包含捕获的文本输出和进程的退出状态。
- 属性
例外
fileName 是 null。
fileName 为空。
cancellationToken读取重定向的流时取消了该操作。
注解
如果在读取重定向流时发生取消,该方法将尝试终止进程并引发 OperationCanceledException。 如果在完全读取流后发生取消,但在等待进程退出时,将终止进程,并且返回的进程已