I have a powershell script which is invoked by the task scheduler. The task's definition also redirects the output using >> to a log file. The PowerShell script invokes a C# console program which generates output which is longer than 80 characters in width. However, the resultant output in the log file is wrapping all the output from the C# program to 80- characters. Note that only the output from the C# program is wrapped. All other output from the script (generated by Write-Host) is not wrapped. Also note that this wrapping only occurs when the script is run by the task scheduler.
Here is the script calling chain:
The task definition invokes a .cmd script (RunWidthTest.cmd)
RunWidthTest.cmd: powershell -File .\RunReports.ps1 >> C:\Log\output.log
RunReports.ps1 (snippet):
Write-Host "======================================================== Running reports for date file for $valueDate"
.\ReportRunner.exe --ValueDate $valueDate | Out-Default
Note that piping the outout to Out-Default is required to avoid another powershell error that occurs due to the fact that an executable's output is attempting to write to the same stream as the powershell script without powershell being aware of it (Write-Host : The OS handle's position is not what FileStream expected. Do not use a handle simultaneously in one FileStream and in Win32 code or another FileStream. This may cause data loss.)
So in this case here, the string output by the Write-Host line is not wrapped, however, any output generated by ReportRunner.exe is wrapped to 80 characters and it only occurs when run with the task scheduler! The same behaviour occurs if you change the point at which the redirection occurs, ie if you redirect in the definition the task (the task's command line instead of inside the script)
Any clues as to why this would occur and how to override this width restriction.
Thanks.