Language

Process.RunAndCaptureTextAsync Method

Definition

Overloads

Name Description
RunAndCaptureTextAsync(ProcessStartInfo, CancellationToken)

Asynchronously 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.

RunAndCaptureTextAsync(String, IEnumerable<String>, CancellationToken)

Asynchronously 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.

RunAndCaptureTextAsync(ProcessStartInfo, CancellationToken)

Source:
Process.Scenarios.cs

Asynchronously 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.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)

Parameters

startInfo
ProcessStartInfo

The ProcessStartInfo that contains the information used to start the process.

cancellationToken
CancellationToken

A token to cancel the asynchronous operation. If the token is canceled, the process is killed.

Returns

A task that represents the asynchronous operation. The value of the task contains the captured text output and exit status of the process.

Attributes

Exceptions

startInfo is null.

The cancellationToken was canceled while reading the redirected streams.

Remarks

If cancellation occurs while reading the redirected streams, the method attempts to kill the process and throws OperationCanceledException. If cancellation occurs after the streams have been fully read but while waiting for the process to exit, the process is killed and the returned ExitStatus has Canceled set to true.

Applies to

RunAndCaptureTextAsync(String, IEnumerable<String>, CancellationToken)

Source:
Process.Scenarios.cs

Asynchronously 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.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)

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.

cancellationToken
CancellationToken

A token to cancel the asynchronous operation. If the token is canceled, the process is killed.

Returns

A task that represents the asynchronous operation. The value of the task contains the captured text output and exit status of the process.

Attributes

Exceptions

fileName is null.

fileName is empty.

The cancellationToken was canceled while reading the redirected streams.

Remarks

If cancellation occurs while reading the redirected streams, the method attempts to kill the process and throws OperationCanceledException. If cancellation occurs after the streams have been fully read but while waiting for the process to exit, the process is killed and the returned ExitStatus has Canceled set to true.

Applies to