LND
LND

Reputation: 152

Git add --verbose output not captured in Powershell verbose stream

When I run "git add . --verbose" I get messages showing the files that are being added like this:

add 'file1.txt"
add 'file2.txt"

But when I run the same git command in C# via PowerShellInstance.BeginInvoke(), the verbose messages are not being redirected to Streams.Verbose. In fact, they are not being redirected to any of the Streams. What am I missing? Is there anything wrong with the code?

Here's my code:

var ps = PowerShell.Create();
ps.Streams.Verbose.DataAdded += VerboseStream_DataAdded;
ps.BeginInvoke<PSObject, PSObject>(null, output);

void VerboseStream_DataAdded(object sender, DataAddedEventArgs e)
{
   // this is never called
}

Upvotes: 1

Views: 314

Answers (2)

LeGEC
LeGEC

Reputation: 51830

From what I grasp about streams in Powershell (I glanced at this article ), it looks like a process in Powershell may write to 5 different output streams.

AFAIK, git was written with a unix like setup in mind, and is only "aware" of two output streams : stdout and stderr. I didn't look at the code, but I highly doubt git's codebase was adapted to take into account those five streams on Windows.


In your Powershell code : try pluging your callback to the Error stream or the Success stream.

Upvotes: 1

VonC
VonC

Reputation: 1323803

Maybe this is because of the git add command making an output on stderr, instead of stdout.
With Git 2.16+ (as I show here), you can try:

set GIT_REDIRECT_STDERR=2>&1

But that might be ignored by a Csharp Git program.

Upvotes: 1

Related Questions