Process.RunAndCaptureText Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
| RunAndCaptureText(String, IEnumerable<String>, Nullable<TimeSpan>) |
Starts a process with the specified file name and optional arguments, captures its standard output and error, waits for it to exit, and returns the captured text and exit status. |
| RunAndCaptureText(ProcessStartInfo, Nullable<TimeSpan>) |
Starts the process described by |
RunAndCaptureText(String, IEnumerable<String>, Nullable<TimeSpan>)
- Source:
- Process.Scenarios.cs
Starts a process with the specified file name and optional arguments, captures its standard output and error, waits for it to exit, and returns the captured text and exit status.
[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
Parameters
- fileName
- String
The name of the executable to start.
- arguments
- IEnumerable<String>
The command-line arguments to pass to the process. Pass null or an empty sequence to start the process without additional arguments.
The maximum amount of time to wait for the process to exit. When null, waits indefinitely. If the process does not exit within the specified timeout, it is killed.
Returns
The captured text output and exit status of the process.
- Attributes
Exceptions
timeout, truncated to a whole number of milliseconds, is less than -1 or greater than MaxValue.
fileName is null.
fileName is empty.
The redirected streams were not fully read within the specified timeout.
Remarks
If the timeout expires while reading the redirected streams, the method attempts to kill the process and throws TimeoutException. If the streams have been fully read but the process doesn't exit within the remaining timeout, the process is killed and the returned ExitStatus has Canceled set to true.
Applies to
RunAndCaptureText(ProcessStartInfo, Nullable<TimeSpan>)
- Source:
- Process.Scenarios.cs
Starts the process described by startInfo, captures its standard output and error, waits for it to exit, and returns the captured text and exit status.
[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
Parameters
- startInfo
- ProcessStartInfo
The ProcessStartInfo that contains the information used to start the process.
The maximum amount of time to wait for the process to exit. When null, waits indefinitely. If the process does not exit within the specified timeout, it is killed.
Returns
The captured text output and exit status of the process.
- Attributes
Exceptions
timeout, truncated to a whole number of milliseconds, is less than -1 or greater than MaxValue.
startInfo is null.
UseShellExecute is set to true.
-or-
RedirectStandardOutput or RedirectStandardError is not set to true.
The redirected streams were not fully read within the specified timeout.
Remarks
If the timeout expires while reading the redirected streams, the method attempts to kill the process and throws TimeoutException. If the streams have been fully read but the process doesn't exit within the remaining timeout, the process is killed and the returned ExitStatus has Canceled set to true.