Capturing Intermediate Output in C# PowerShell CmdLet using yt-dlp

Will Pittenger 311 Reputation points
2025-02-16T11:32:48.65+00:00

How can intermediate status messages be displayed to the user and logged while executing the yt-dlp command in a C# CmdLet? I've created a System.Diagnostics.Process to execute yt-dlp, but I need to provide it access to the console for real-time output, similar to running it directly from the command line. Using Host.UI.WriteLine may strip colors, and I need to ensure that yt-dlp's dynamic updates to the console are visible. Additionally, I need to capture any JSON output that yt-dlp generates before it completes, which I believe will be in Standard Output. How can this be achieved?

Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Client for IT Pros | User experience | Other
Developer technologies | .NET | Other
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    2025-02-16T16:46:18.4566667+00:00

    You redirect standard output and error to streams to capture them. See

    https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.standardoutput?view=net-9.0


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.