Skip to content

[API Proposal]: Process.RunAndCaptureLinesAsync for reading output lines streaming #128280

@WeihanLi

Description

@WeihanLi

Background and motivation

Since we've introduced some new APIs for Process

wondering that maybe we could also add static methods Process.RunAndCaptureLinesAsync likes Process.RunAndCaptureTextAsync to simplify the read process output lines as a stream

API Proposal

namespace System.Diagnostics;

public class Process
{
    public static IAsyncEnumerable<ProcessOutputLine> RunAndCaptureLinesAsync(string fileName, IList<string>? arguments = null, CancellationToken cancellationToken = default);
    public static IAsyncEnumerable<ProcessOutputLine> RunAndCaptureLinesAsync(ProcessStartInfo startInfo, CancellationToken cancellationToken = default);
}

API Usage

await foreach (var line in Process.RunAndCaptureLinesAsync("dotnet", ["--info"]))
{
    ConsoleHelper.WriteLineWithColor(line.Content, line.StandardError ? ConsoleColor.Red : ConsoleColor.Green);
}

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Diagnostics.ProcessuntriagedNew issue has not been triaged by the area owner

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions