語言

Process.RunAndCaptureText 方法

定義

多載

名稱 Description
RunAndCaptureText(String, IEnumerable<String>, Nullable<TimeSpan>)

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

RunAndCaptureText(ProcessStartInfo, Nullable<TimeSpan>)

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

RunAndCaptureText(String, IEnumerable<String>, Nullable<TimeSpan>)

來源:
Process.Scenarios.cs

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

[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
Nullable<TimeSpan>

等待流程結束的最大等待時間。 當 null,則無限期等待。 若程序未在指定逾時內退出,則終止。

傳回

擷取的文字輸出與程序的退出狀態。

屬性

例外狀況

timeout截斷為整數毫秒後,小於 -1 或大於 MaxValue。

fileName 是 null。

fileName 空無一人。

重定向的串流並未在指定 timeout範圍內完整讀取。

備註

如果讀取重定向串流時逾時結束,方法會嘗試終止程序並拋 TimeoutException出 。 如果串流已被完全讀取,但程序在剩餘逾時內未退出,則程序會被終止,返回 ExitStatus 的程序會 Canceled 被設定為 true。

適用於

RunAndCaptureText(ProcessStartInfo, Nullable<TimeSpan>)

來源:
Process.Scenarios.cs

啟動由 描述的 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
Nullable<TimeSpan>

等待流程結束的最大等待時間。 當 null,則無限期等待。 若程序未在指定逾時內退出,則終止。

傳回

擷取的文字輸出與程序的退出狀態。

屬性

例外狀況

timeout截斷為整數毫秒後,小於 -1 或大於 MaxValue。

startInfo 是 null。

UseShellExecute 設定為 true。

-或者-

RedirectStandardOutput 或 RedirectStandardError 未設定為 true。

重定向的串流並未在指定 timeout範圍內完整讀取。

備註

如果讀取重定向串流時逾時結束,方法會嘗試終止程序並拋 TimeoutException出 。 如果串流已被完全讀取,但程序在剩餘逾時內未退出,則程序會被終止,返回 ExitStatus 的程序會 Canceled 被設定為 true。

適用於