Reputation: 103
ok so in a nut shell, I've got PowerShell driving YUI Compressor to do some JS compression as part of a visual studios pre-build event. though syntax errors are likely to be very infrequent, I'd like to know about those errors if they do occur and with the script I have running now, I have not been able to have Visual Studios display the errors in the build log or to have the powershell script write any errors YUI gives to a .txt file to be viewed later. (the latter would be the preferred)
Write-Host "Working in $args"
attrib -R $args*.* /s
Get-ChildItem $args -include *.js -recurse -force | %{java -jar C:\Tools\yuicompressor-2.4.6\build\yuicompressor-2.4.6.jar ($.fullname) -o ($.fullname) --type js --nomunge}
Write-Host in the PowerShell script allows me to then create a .txt with the output using the following cmd in Visual Studios:
powershell.exe -file "$(ProjectDir)....\PowerScripts\Pre_Build_Public.ps1">> “C:\Tools\Pre_Build_Report.txt” "$(ProjectDir)Scripts"
would this work with any errors given from YUI as well?
If more clarification is needed, please let me know. I want to make this as easy as possible and thanks for taking the time to look this over.
Upvotes: 0
Views: 431
Reputation: 26769
You can redirect the stderr stream using the 2>&1
operator:
powershell.exe -file "$(ProjectDir)....\PowerScripts\Pre_Build_Public.ps1" 2>&1 >> "C:\Tools\Pre_Build_Report.txt" "$(ProjectDir)Scripts"
I believe, however, that PowerShell's internal error handling doesn't write to stderr. You'll need to do that by hand. At the end of your Pre_Build_Public.ps1
script, I'd do something like:
foreach( $err in $error )
{
Write-Output $err
}
This will send each error to stdout.
It looks like PowerShell v3 will support redirecting PowerShell's internal error stream.
Upvotes: 0