Unable to retrieve stderror and stdout when calling a Powershell script from SSIS

旧街凉风 提交于 2021-01-27 20:31:54

问题


I have an SSIS package that calls some powershell scripts to consume web services. The problem is that when I write to stderror or stdout, the StandardErrorVariable and StandardOutputVariable are not picking up anything that is written to them from the script.

The scripts execute just fine, so it isn't a problem with calling the script it just seems as if the standard output streams are not coming back to SSIS. Here's how the Execute Process task is set up:

I've tried various ways of writing output from powershell. Most sources seem to indicate Write-Information should work for stdout, and I'm using mklement0's answer in this thread but have also tried Write-Error and neither worked: How do I write to standard error in PowerShell?

Any ideas?


回答1:


I use Write-Host to output to stdout, and write-Error "Message" -ErrorAction Stop to write to stdout. I recall having issues using Write-Error without specifying that I wanted a terminating error, so try to set the ErrorPreference with each Write-Error or by setting $ErrorPreference early in your script. As mentioned in the comments there is some funkyness regarding the way powershell streams work that I do not understand/others could explain why way better than I can.

Another thing is I always set WindowStyle to Hidden. I am not sure how that would affect the stdout/err/in streams, but that has saved me other headaches when running PS from inside of SSIS.



来源:https://stackoverflow.com/questions/64343915/unable-to-retrieve-stderror-and-stdout-when-calling-a-powershell-script-from-ssi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!