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