Problem
I am trying to capture the STDERR
outputs into a log file; however, I have been encountering some serious inconsistent issues that are making my task harder.
First off, I have my ErrorActionPreference
to 'Stop', which is probably part of the problems I am enduring.
Second, I have tried two variants for EACH git command in my code displayed below:
Variant 01
& git add $path2File 2>&1 | Out-File "$LogPath\$tmpLogName" -Append
& git commit -m "Some logical update message" 2>&1 | Out-File "$LogPath\$tmpLogName" -Append
& git status 2>&1 | Out-File "$LogPath\$tmpLogName" -Append
& git push 2>&1 | Out-File "$LogPath\$tmpLogName" -Append
Variant 02
& git add $path2File 2>&1 >> "$LogPath\$tmpLogName" -Append
& git commit -m "Some Logical update message" 2>&1 >> "$LogPath\$tmpLogName" -Append
& git status 2>&1 >> "$LogPath\$tmpLogName" -Append
& git push 2>&1 >> "$LogPath\$tmpLogName" -Append
There were several other variants in which I mixed up which command used which variant depending upon common issues I had encountered.
The primary issues I have been encountering are:
1) whenever an STDERR
output is encountered, it is treated as a terminating error, regardless of the message.
2) My attempts to create custom Try/Catch
statements have failed due to a number of reasons. Exit Codes were not always the same for successful STDERR
messages. Couldn't use plain text matches for anything beyond warnings due to messages not always using the same or similar messages.
NOTE: I am trying to do this without changing the ErrorActionPreference
unless absolutely necessary.
Question
Does anyone know how to handle logging the STDERR
messages for git commands so that it always logs the responses without throwing a terminating error except for true critical errors?