1

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
}
LND
  • 142
  • 9

2 Answers2

1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I checked the link you provided. It talks about git push --porcelain. Unfortunately, git add does not have a --porcelain option. In my C# code, I also check for output to Streams.Error (I assume this is stderr), and no verbose output is redirected there. – LND Jan 21 '19 at 16:47
1

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.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Actually, in my C# code, I have callbacks for the 5 PowerShell streams. Only the Error callback gets called. Perhaps your suspicion that git's codebase was not adapted to take advantage of the 5 streams in Windows is correct. I hope someone can confirm this. The discussion of Write-Host in the article you suggested was very helpful. I suspect that git's verbose output is written using Write-Host and not Write-Verbose. Again, I hope someone can confirm this. – LND Jan 21 '19 at 17:14