How to keep git-sdk output to parent Powershell?

Viewed 35

I am running a bunch of git commands, as well as make and gcc through the Git SDK on Windows. I am doing this through Powershell. My code looks like this:

& 'C:\git-sdk-64\git-bash.exe' -lc 'git status'

As you can see, I'm using the call operator, which means that whenever the git-bash.exe is called, it opens in a new window where all of it's output is sent, and then the window closes and the output is lost. How can I redirect this output to the parent Powershell instance? I tried using Invoke-Command, Invoke-Expression and Start-Process, but I couldn't figure out a configuration that works.

UPDATE: I tried using Start-Process again, and got it to run:

Start-Process -Wait 'C:\git-sdk-64\git-bash.exe' -ArgumentList "-lc 'git status'" -NoNewWindow

As you can see, I'm using the NoNewWindow argument, and still a new window is being opened.

1 Answers

Well, I figured it out. It's an incredibly hacky solution, but it works. In the specified parameters of the bash console, I include a redirect, like this:

Start-Process -Wait 'C:\git-sdk-64\git-bash.exe' -ArgumentList "-lc 'git status &>tmpgitout'"

After this, I simply read the file from Powershell, and then delete it:

Get-Content tmpgitout
Remove-Item tmpgitout

This is, unfortunately, the best solution I can find.

Related