You need to run git status from a .NET tool and capture the result.

That sounds like five lines of code. The old Process API could turn it into redirection settings, output events, error events, task completion sources, and a small prayer that both streams finish before the process exits.

.NET 11 adds one-shot process helpers for the common case.

This tip uses .NET 11 Preview 7. Preview APIs can change before the final release.

Try It

Install the .NET 11 Preview 7 SDK, then create a console app:

Terminal window
dotnet new console -n ProcessCaptureDemo -f net11.0
cd ProcessCaptureDemo

Replace Program.cs with this:

using System.Diagnostics;
ProcessTextOutput result = await Process.RunAndCaptureTextAsync(
"git",
["status", "--short"]);
Console.WriteLine($"Exit code: {result.ExitStatus.ExitCode}");
if (!string.IsNullOrWhiteSpace(result.StandardOutput))
{
Console.WriteLine("Standard output:");
Console.WriteLine(result.StandardOutput);
}
if (!string.IsNullOrWhiteSpace(result.StandardError))
{
Console.WriteLine("Standard error:");
Console.WriteLine(result.StandardError);
}

Run it from any Git repository:

Terminal window
dotnet run

You get standard output, standard error, and the exit code in one result. No event handlers required.

Stream Output as It Arrives

When you need live progress instead of one final string, .NET 11 also adds ReadAllLinesAsync:

using var process = Process.Start(new ProcessStartInfo
{
FileName = "dotnet",
Arguments = "--info",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false
})!;
await foreach (ProcessOutputLine line in
process.ReadAllLinesAsync(CancellationToken.None))
{
var label = line.StandardError ? "ERR" : "OUT";
Console.WriteLine($"[{label}] {line.Content}");
}

The output type tells you which stream produced each line, so you don’t have to merge two event pipelines yourself.

When Not to Use It

RunAndCaptureTextAsync holds the captured text in memory. That is perfect for a command such as git status. It is not the right choice for a process that can print gigabytes or run forever. Stream those lines or redirect them to a file instead.

Key Takeaway

.NET 11 gives Process a much friendlier path for running commands and collecting results. Use the one-shot helper for bounded output. Use the async line stream when you need progress as it happens.