Fixed issue 3729

The logic used to read the file contents sometimes would leave lines behind unread. It now defaults to reading all lines and counts each line it has actually read.
This commit is contained in:
Shawn Neal 2014-05-15 09:17:57 -07:00
parent 3fb7b5061e
commit 823e80fa32
1 changed files with 12 additions and 14 deletions

View File

@ -71,25 +71,23 @@ while ( (!($registered_task.state -eq 4)) -and ($sec -lt $timeout) ) {
$sec++ $sec++
} }
# Read the entire file, but only write out new lines we haven't seen before function SlurpOutput($out_file, $cur_line) {
$numLinesRead = 0
do {
Start-Sleep -m 100
if (Test-Path $out_file) { if (Test-Path $out_file) {
$text = (get-content $out_file) get-content $out_file | select -skip $cur_line | ForEach {
$numLines = ($text | Measure-Object -line).lines $cur_line += 1
$numLinesToRead = $numLines - $numLinesRead Write-Host "$_"
if ($numLinesToRead -gt 0) {
$text | select -first $numLinesToRead -skip $numLinesRead | ForEach {
Write-Host "$_"
}
$numLinesRead += $numLinesToRead
} }
} }
return $cur_line
}
$cur_line = 0
do {
Start-Sleep -m 100
$cur_line = SlurpOutput $out_file $cur_line
} while (!($registered_task.state -eq 3)) } while (!($registered_task.state -eq 3))
$exit_code = $registered_task.LastTaskResult $exit_code = $registered_task.LastTaskResult
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($schedule) | Out-Null [System.Runtime.Interopservices.Marshal]::ReleaseComObject($schedule) | Out-Null
exit $exit_code exit $exit_code