Tim Meyer
Tim Meyer

Reputation: 12600

Why does PowerShell.Invoke contain regular messages in the error stream

I am using Microsoft.PowerShell.SDK (Version 7.3.3) in order to clone a git repository from C# like this:

(Note: I know there is libgit2sharp, but it doesn't support all of my use cases).

    using (var ps = PowerShell.Create())
    {
        ps.AddScript($"git clone {url} {localPath}");
        ps.Invoke();
        if (ps.HadErrors)
        {
            Console.WriteLine("Errors occurred: ");
            foreach (var error in ps.Streams.Error)
            {
                Console.WriteLine(error.ToString());
            }
        }
    }

When successfully pulling a repository with that, I get the following output on the console:

Errors occurred:

Cloning into '<local path>' ...

Why does the informational output end up in the error stream?

Upvotes: 0

Views: 47

Answers (1)

Tim Meyer
Tim Meyer

Reputation: 12600

Thanks to @madreflection 's comment, I found out this is a specialty of git

Adding the --quiet flag will cause git to only report actual errors to the error stream and be silent in any "good" case (Compare documentation here):

ps.AddScript($"git clone {url} {localPath} --quiet");

Upvotes: 0

Related Questions