Process.RunAndCaptureText 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
| 名稱 | Description |
|---|---|
| RunAndCaptureText(String, IEnumerable<String>, Nullable<TimeSpan>) |
啟動一個以指定檔案名稱和可選參數的程序,擷取其標準輸出與錯誤,等待其退出,並回傳擷取的文字與退出狀態。 |
| RunAndCaptureText(ProcessStartInfo, Nullable<TimeSpan>) |
啟動由 描述的 |
RunAndCaptureText(String, IEnumerable<String>, Nullable<TimeSpan>)
啟動一個以指定檔案名稱和可選參數的程序,擷取其標準輸出與錯誤,等待其退出,並回傳擷取的文字與退出狀態。
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.ProcessTextOutput RunAndCaptureText(string fileName, System.Collections.Generic.IEnumerable<string>? arguments = default, TimeSpan? timeout = default);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member RunAndCaptureText : string * seq<string> * Nullable<TimeSpan> -> System.Diagnostics.ProcessTextOutput
Public Shared Function RunAndCaptureText (fileName As String, Optional arguments As IEnumerable(Of String) = Nothing, Optional timeout As Nullable(Of TimeSpan) = Nothing) As ProcessTextOutput
參數
- fileName
- String
執行檔名稱作為起始。
- arguments
- IEnumerable<String>
命令列參數,傳遞給程序。 通過 null 或空序列即可啟動程序,無需額外參數。
傳回
擷取的文字輸出與程序的退出狀態。
- 屬性
例外狀況
timeout截斷為整數毫秒後,小於 -1 或大於 MaxValue。
fileName 是 null。
fileName 空無一人。
重定向的串流並未在指定 timeout範圍內完整讀取。
備註
如果讀取重定向串流時逾時結束,方法會嘗試終止程序並拋 TimeoutException出 。 如果串流已被完全讀取,但程序在剩餘逾時內未退出,則程序會被終止,返回 ExitStatus 的程序會 Canceled 被設定為 true。
適用於
RunAndCaptureText(ProcessStartInfo, Nullable<TimeSpan>)
啟動由 描述的 startInfo程序,擷取其標準輸出與錯誤,等待其退出,並回傳擷取的文字與退出狀態。
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.ProcessTextOutput RunAndCaptureText(System.Diagnostics.ProcessStartInfo startInfo, TimeSpan? timeout = default);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member RunAndCaptureText : System.Diagnostics.ProcessStartInfo * Nullable<TimeSpan> -> System.Diagnostics.ProcessTextOutput
Public Shared Function RunAndCaptureText (startInfo As ProcessStartInfo, Optional timeout As Nullable(Of TimeSpan) = Nothing) As ProcessTextOutput
參數
- startInfo
- ProcessStartInfo
那個 ProcessStartInfo 包含啟動流程所使用的資訊。
傳回
擷取的文字輸出與程序的退出狀態。
- 屬性
例外狀況
timeout截斷為整數毫秒後,小於 -1 或大於 MaxValue。
startInfo 是 null。
重定向的串流並未在指定 timeout範圍內完整讀取。
備註
如果讀取重定向串流時逾時結束,方法會嘗試終止程序並拋 TimeoutException出 。 如果串流已被完全讀取,但程序在剩餘逾時內未退出,則程序會被終止,返回 ExitStatus 的程序會 Canceled 被設定為 true。