Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to redirect Powershell output from a script run by TaskScheduler and override default width of 80 characters
    primarykey
    data
    text
    <p>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.</p> <p>Here is the script calling chain:</p> <ul> <li><p>The task definition invokes a .cmd script (RunWidthTest.cmd)</p></li> <li><p>RunWidthTest.cmd: powershell -File .\RunReports.ps1 >> C:\Log\output.log</p></li> <li><p>RunReports.ps1 (snippet):</p> <p>Write-Host "======================================================== Running reports for date file for $valueDate"</p> <p>.\ReportRunner.exe --ValueDate $valueDate | Out-Default</p></li> </ul> <p>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 (<em>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.</em>)</p> <p>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)</p> <p>Any clues as to why this would occur and how to override this width restriction.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload