语言

Process.RunAndCaptureText 方法

定义

重载

名称 说明
RunAndCaptureText(String, IEnumerable<String>, Nullable<TimeSpan>)

使用指定的文件名和可选参数启动进程,捕获其标准输出和错误,等待它退出,并返回捕获的文本和退出状态。

RunAndCaptureText(ProcessStartInfo, Nullable<TimeSpan>)

启动所 startInfo描述的过程,捕获其标准输出和错误,等待其退出,并返回捕获的文本和退出状态。

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

Source:
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>)

Source:
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。

适用于