語言

Process.RunAndCaptureTextAsync 方法

定義

多載

名稱 Description
RunAndCaptureTextAsync(ProcessStartInfo, CancellationToken)

非同步啟動由描述的 startInfo程序,擷取其標準輸出與錯誤,等待其退出,並回傳擷取的文字與退出狀態。

RunAndCaptureTextAsync(String, IEnumerable<String>, CancellationToken)

非同步啟動一個以指定檔案名稱和可選參數的程序,擷取其標準輸出與錯誤,等待其退出,並回傳擷取的文字與退出狀態。

RunAndCaptureTextAsync(ProcessStartInfo, CancellationToken)

來源:
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。

UseShellExecute 設定為 true。

-或者-

RedirectStandardOutput 或 RedirectStandardError 未設定為 true。

在閱讀重定向串流時,節目 cancellationToken 被取消了。

備註

若在讀取重定向串流時發生消去,該方法會嘗試終止程序並拋 OperationCanceledException出 。 若在串流完全讀取後且等待程序退出時取消,程序會被終止,回傳 ExitStatus 的程序將 Canceled 設定為 true。

適用於

RunAndCaptureTextAsync(String, IEnumerable<String>, CancellationToken)

來源:
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出 。 若在串流完全讀取後且等待程序退出時取消,程序會被終止,回傳 ExitStatus 的程序將 Canceled 設定為 true。

適用於